no current record - close form (1 Viewer)

MartijnR

Registered User.
Local time
Today, 04:17
Joined
Oct 18, 2002
Messages
60
no current record - close form - on_current?

Hi,

on a form with several subforms i have ran into some trouble. I have the subforms use code to determine if a scrollbar is needed. As a recordselector I use a listbox on the main form.

When i close the mainform, it sometimes makes a popup box appear saying that there is no current record.

Sofar I have determined the following :

- Removing the code from the form, removes the error.

- The code is only executed when selected records in the listbox have related record(s)

- The error only occurs when the code is executed at least once and the last selected record has no related record(s)

I dont know if altering the code would have any success, cause it won't run anyway when I select the last record (with no related records).

I guess moving the code to another section would be better, but I've tried other options like 'on focus' etc, but could not find one that responded.

HELP PLZ :)


Private Sub Form_Current()
On Error GoTo Error

'kijken of verticale scrollbar nodig is
maxRegels = 14

Dim rstCount As DAO.Recordset
Set rstCount = Me.Recordset
If rstCount.RecordCount > maxRegels Then
Me.Form.ScrollBars = 2
Else
Me.Form.ScrollBars = 0
End If

Error:
If Err.Number <> "0" Then
Else
MsgBox Err.Number & " " & Err.Description
End If
Exit Sub

End Sub

ps. I've tried to catch err.Number = "3021" in the Error: section, but without success
 
Last edited:

carash77ash

Registered User.
Local time
Today, 13:17
Joined
Jan 13, 2006
Messages
81
try nesting if statement first to tell sub to do nothing if there is no related records.
eg

Dim rstCount As DAO.Recordset
Set rstCount = Me.Recordset
if rstCount.RecordCount = 0 then
else
If rstCount.RecordCount > maxRegels Then
Me.Form.ScrollBars = 2
Else
Me.Form.ScrollBars = 0
End If
end if

Hope this helps
Ash
 

MartijnR

Registered User.
Local time
Today, 04:17
Joined
Oct 18, 2002
Messages
60
Hi, thanks for replying

I've tried things like that, but the code won't run if there are no related records :)

edit: funny thing is that when I place a msgbox ("test") at the beginning of the code, I get 2 boxes saying test when I select a record which has related records and 0 boxes with a record with no related records

I can only imagine that setting of the scrollbar property triggers another on_current action, that's why I get 2 boxes. But this is just a guess :)
 
Last edited:

MartijnR

Registered User.
Local time
Today, 04:17
Joined
Oct 18, 2002
Messages
60
Eh, I can only post messages

What part of the db do you need, i can try copy/paste etc.

Btw, I think it's more related to the on_current action causing the error, because when I close the form (that's only when it happens) I get the error. I can imagine the subform trying to execute the code, but the 'rest' , the listbox,queries,etc. are allready gone/closed.

But then again, this is also a guess :)
 
Last edited:

carash77ash

Registered User.
Local time
Today, 13:17
Joined
Jan 13, 2006
Messages
81
if you zip the db and then go to advanced reply there you can attach the zip file.

ash
 

Users who are viewing this thread

Top Bottom