DLookup

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi,

I have a subform with a record source based on a query.
That query asks two things (Employee ID and NT Name). I
am trying to get the subform to not open if the query
returns no records. So, if the user enters something that
does not equal a record... a message box appears and the
subform is not opened. I tried the following, but it is
not working. How can I get this to work? Thanks!!!!


Private Sub Form_Open(Cancel As Integer)

If IsNull(DLookup_
("EmployeeID", "queryEmployeePassword")) Then
MsgBox "The Employee ID and NT Logon is not_
valid.", vbCritical, "Notice:"
ElseIf IsNull(DLookup_
("NTName", "queryEmployeePassword")) Then
MsgBox "The Employee ID and NT Logon is not_
valid.", vbCritical, "Notice:"

End If
End Sub
 
Mark said:
Hi,

I have a subform with a record source based on a query.
That query asks two things (Employee ID and NT Name). I
am trying to get the subform to not open if the query
returns no records. So, if the user enters something that
does not equal a record... a message box appears and the
subform is not opened. I tried the following, but it is
not working. How can I get this to work? Thanks!!!!


Private Sub Form_Open(Cancel As Integer)

If IsNull(DLookup_
("EmployeeID", "queryEmployeePassword")) Then
MsgBox "The Employee ID and NT Logon is not_
valid.", vbCritical, "Notice:"
ElseIf IsNull(DLookup_
("NTName", "queryEmployeePassword")) Then
MsgBox "The Employee ID and NT Logon is not_
valid.", vbCritical, "Notice:"

End If
End Sub

A subform refers to a form embedded within another form. Is that what you
have? If so, what do you want to see where the subform would be when it is
not opened? Just a white box? You could just hide the subform control in
that case.

If what you really mean is a form that you open from another form then what
you have above will work if you add a Cancel = True. You are performing
two "If-Tests", but then you aren't doing anything with them except
displaying messages. It is the Cancel = True that prevent the form from
opening.
 
Hey Rick,

You are right about using the cancel = true statement.

However, when I try opening the subform using my code
below.. I get a run time error '2471' stating: the
expression you entered as a query parameter produced this
error: 'The object doesn't contain the Automation
object 'Enter your Emloyee ID:'

Not sure why this is happening??? What is another way to
get around this? Should I just use something with the
recordsetclone equaling zero which closes the form?

Thanks!!!
 
Hey Rick,

I believe this is working:


If IsNull(Me.NTName) Then
MsgBox "The Employee ID and NT Logon is not
valid.", vbCritical, "Notice:"
Cancel = True

End If


Thanks for helping!!!
 
Back
Top