MsgBox not displaying

  • Thread starter Thread starter Ian Baker
  • Start date Start date
I

Ian Baker

Hi - Using A2003 in A2000 format I have a form (bound to a query) with a
subform (also bound to a query). The main form has an unbound check box
(ctlAuthorised) that when clicked I need it to check to see if all the
records in the subform have an entry in a field "CategoryID". Here is my
code:
Dim rst As Recordset

Set rst = Me!subAccountPayable.Form.RecordsetClone

rst.FindFirst "CategoryID Is Null"

If rst.NoMatch = False Then
ctlAuthorised = False
MsgBox "Please enter or select a category for each of the items.", _
vbExclamation, "Missing Category"
End If

rst.Close
Set rst = Nothing

If I step through the code it works ok but if I don't the msgbox is "not
displayed" although the msgbox has been initiated thereby hanging the app
until I press Enter.
 
The msgbox is being displayed but behind the form. I tried it with the form
off center and the msgbox is displayed. The form isn't popup or modal.
 
Ian Baker said:
Hi - Using A2003 in A2000 format I have a form (bound to a query)
with a subform (also bound to a query). The main form has an unbound
check box (ctlAuthorised) that when clicked I need it to check to see
if all the records in the subform have an entry in a field
"CategoryID". Here is my code:
Dim rst As Recordset

Set rst = Me!subAccountPayable.Form.RecordsetClone

rst.FindFirst "CategoryID Is Null"

If rst.NoMatch = False Then
ctlAuthorised = False
MsgBox "Please enter or select a category for each of the
items.", _ vbExclamation, "Missing Category"
End If

rst.Close
Set rst = Nothing

If I step through the code it works ok but if I don't the msgbox is
"not displayed" although the msgbox has been initiated thereby
hanging the app until I press Enter.

Two things, which may or may not be related to your problem:

1. What event are you using to execute this code? You may be getting
hung up if you're using the the Click or BeforeUpdate event, since your
code attempts to change the value of ctlAuthorised at the same time
Access is trying to change it.

2. Don't close the RecordsetClone! You didn't open it, you shouldn't
close it.

Since this is a data validation process, the check box's BeforeUpdate
event does seem like the most likely event to use for it, but you'd have
to write the code differently. Try this:

'------ start of code ------
Private Sub ctlAuthorised_BeforeUpdate(Cancel As Integer)

If Me.ctlAuthorised = True Then

With Me!subAccountPayable.Form.RecordsetClone
.FindFirst "CategoryID Is Null"
If .NoMatch = False Then
Cancel = True
MsgBox _
"Please enter or select a category for each " & _
"of the items.", _
vbExclamation, "Missing Category"
End If
End With

End If

End Sub
'------ end of code ------
 
Thanks Dirk but unfortunately that code doesn't work either. Please note
that the check box [ctlAuthorised] isn't bound to anything.
 
Solved it. I have noticed that when using A2003 and A2003 ONLY (i.e. no
problems with A2002, A2000 or A97 on this box) that calculated controls on
some of my subforms don't display their values when the form first opens
until I move the mouse over the subform (why I do not know as I said it is
only with A2003). To resolve this problem if I put a Me.Recalc at the
beginning of the code it works ok. hmmmm strange

--
Regards
Ian Baker
(If a=ian, b=jackaroo, c=net, d=au then me= (e-mail address removed))
-
Ian Baker said:
Thanks Dirk but unfortunately that code doesn't work either. Please note
that the check box [ctlAuthorised] isn't bound to anything.

--
Regards
Ian Baker
(If a=ian, b=jackaroo, c=net, d=au then me= (e-mail address removed))
-
Dirk Goldgar said:
Two things, which may or may not be related to your problem:

1. What event are you using to execute this code? You may be getting
hung up if you're using the the Click or BeforeUpdate event, since your
code attempts to change the value of ctlAuthorised at the same time
Access is trying to change it.

2. Don't close the RecordsetClone! You didn't open it, you shouldn't
close it.

Since this is a data validation process, the check box's BeforeUpdate
event does seem like the most likely event to use for it, but you'd have
to write the code differently. Try this:

'------ start of code ------
Private Sub ctlAuthorised_BeforeUpdate(Cancel As Integer)

If Me.ctlAuthorised = True Then

With Me!subAccountPayable.Form.RecordsetClone
.FindFirst "CategoryID Is Null"
If .NoMatch = False Then
Cancel = True
MsgBox _
"Please enter or select a category for each " & _
"of the items.", _
vbExclamation, "Missing Category"
End If
End With

End If

End Sub
'------ end of code ------

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Ian Baker said:
Thanks Dirk but unfortunately that code doesn't work either. Please
note that the check box [ctlAuthorised] isn't bound to anything.

I noted that; I don't think it's relevant. So you got the same result
with that code as the original? Hmm. Does your form have a Timer
event?
 
Ian Baker said:
Solved it. I have noticed that when using A2003 and A2003 ONLY (i.e.
no problems with A2002, A2000 or A97 on this box) that calculated
controls on some of my subforms don't display their values when the
form first opens until I move the mouse over the subform (why I do
not know as I said it is only with A2003). To resolve this problem if
I put a Me.Recalc at the beginning of the code it works ok. hmmmm
strange

Huh. I don't have A2003 installed, so I can't check this out. There
are definitely some display bugs in A2003. Maybe this is one of them.
I don't quite see how it's having the effect you report, though.

Anyway, I'm glad to hear you found a solution.
 
Back
Top