Cant finish code

  • Thread starter Thread starter johnson
  • Start date Start date
J

johnson

I have a problem with displaying a message box.
I have a form, form1 which displays a record. At the
bottom of form1 there is some buttons such as physical,
functional, etc which display more data about the record
on show on form1. Sometimes however there is no data for
the record in some of the buttons.
What I want is if there is no data for the record, a
message box to pop up alerting the user to this and giving
them the option to continue or not.
So far I have got.

If IdNumber = "" Then
MsgBox "There is no data for this record. Do you want to
continue?", vbYesNo, "MS Access"
Else


I dont know how to finish this segment. I have applied
this to the event 'On form load'

Please help
 
Hi,
Use the Open event because you can cancel it if neccessary:

Private Sub Form_Open(Cancel As Integer)
Dim intResponse As Integer
If Me.RecordsetClone.RecordCount = 0 Then
intResponse = MsgBox("no records ....", vbOKCancel)
If intResponse = vbCancel Then
Cancel = True
End If
End If

End Sub
 
Hi,

try something like the following (watch the word wrap):

Dim x

If IdNumber = "" Then
x = MsgBox("There is no data for this record. Do you want
to continue?", vbYesNo, "MS Access")
End If

Select Case x
Case vbYes
'code to run if 'yes' clicked
Case vbNo
'code to run if 'No' clicked
Case Else
'code to run in case something else happens
End Select

hth

chas
 
Back
Top