Here is the code:
Private Sub Command107_Click()
Dim strWhere As String
If Not IsNull(Me.[LUST Number]) Then
strWhere = "[LUST Number] = " & Me.[LUST Number]
End If
DoCmd.OpenForm "Correspondence Entry Form", acFormDS,
WhereCondition:=strWhere
But I get a 2501 Run-Time error - HELP!
And what do you want to happen if [LUST Number] is Null?
I'll assume the WhereCondition: was actually placed on the same line
as the rest of the OpenForm code.
Is [LUST Number] a number datatype?
Your syntax is OK.
Or is it Text datatype?
If it is text then the correct strWhere syntax should be:
strWhere = "LUST Number] = '" & Me![LUST Number] & "'"
If that doesn't fix the problem, then place a breakpoint on the If Not
IsNull() line and then step through the code one line at a time. Do
you get the correct value for strWhere?
Continue stepping through the code. You may have code elsewhere
(perhaps in the form Open or Load event) closing the form if there are
no records in it's recordset.
If so modify your above code to include error handling:
On Error GoTo Err_Handler
' Place your existing code here
Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub