Syntax error in DoCmd.OpenForm code (1 Viewer)

lmcc007

Registered User.
Local time
Today, 09:01
Joined
Nov 10, 2007
Messages
635
I have a command button that when clicked it will open a form called Check Addresses. Below is the code:
Private Sub cmdEditAddress_Click()
Me.Requery

DoCmd.OpenForm "frmCheckAddresses", , , "CompanyID=" & CompanyID

End Sub

The above code works fine when there is an address (or one of the address fields is filled out), but when there is no address I get an error instead of a blank Check Address form. The error message is:

Run-time error ‘3075’:

Syntax error (missing operator) in query expression ‘CompanyID=’.

I want a blank form so I can add an address if the address field is blank.

How shall I do that? Any help will be appreciated. Thanks!
 

Attachments

  • test db 2000.zip
    97.7 KB · Views: 109

ajetrumpet

Banned
Local time
Today, 09:01
Joined
Jun 22, 2007
Messages
5,638
try this........
Code:
    Me.Requery
    
    If IsNull(CompanyID) Then
      DoCmd.OpenForm "frmCheckAddresses", , , , acFormAdd
    Else
      DoCmd.OpenForm "frmCheckAddresses", , , "CompanyID=" & CompanyID
   End If
 

lmcc007

Registered User.
Local time
Today, 09:01
Joined
Nov 10, 2007
Messages
635
Thanks Adam!

Exactly what I wanted.
 

Users who are viewing this thread

Top Bottom