Where Condition Error

G

Guest

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!
 
D

Dirk Goldgar

Larry G. said:
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!

What type of field is "LUST Number"? What is the content of strWhere
when OpenForm is called? Is "LUST Number" in the recordsource of
"Correspondence Entry Form"?

And what is *your* Lust Number? ;-)
 
G

Guest

Never mind I - I figured it when I went back and re-read Allen's answer to my
question in November, LUST Number is a text field and so needed extra
quotations.
 
G

Guest

You are missing one comma on the OpenForm command line

DoCmd.OpenForm "Correspondence Entry Form", acFormDS , , strWhere
 
F

fredg

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
 
D

Dirk Goldgar

Ofer said:
You are missing one comma on the OpenForm command line

DoCmd.OpenForm "Correspondence Entry Form", acFormDS , , strWhere

No, because he's using a named argument:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top