By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,481 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,481 IT Pros & Developers. It's quick & easy.

If Then statement not working

P: n/a
If the user dbl clicks the field "vendor" I want it to open frmContacts to a
blank record if there is nothing in the current field and if there is, open
frm Contacts to that record. I have the following code...

If Me.Vendor = Null Then
DoCmd.OpenForm "frmContacts", , , , acFormAdd
Else
DoCmd.OpenForm "frmContacts", , , "ClientID = " & Me!Vendor
End If

If there is a name in the the field "vendor", frmContacts is opened to that
name, if, however, the field is blank, I get an error (runtime 3075) and
access highlights the line docmd...."ClientID =" & Me!Vendor

I seems to me that if that field is blank, access shouldn't be reading that
line since it is the else part of the statement. I put a toggle point on the
the first line and access tells me that Me.Vendor = Null and Null = Null.
Whats going on here? Simple syntax error?
Dec 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Jimmy wrote:
If the user dbl clicks the field "vendor" I want it to open frmContacts to a
blank record if there is nothing in the current field and if there is, open
frm Contacts to that record. I have the following code...

If Me.Vendor = Null Then
DoCmd.OpenForm "frmContacts", , , , acFormAdd
Else
DoCmd.OpenForm "frmContacts", , , "ClientID = " & Me!Vendor
End If

If there is a name in the the field "vendor", frmContacts is opened to that
name, if, however, the field is blank, I get an error (runtime 3075) and
access highlights the line docmd...."ClientID =" & Me!Vendor

I seems to me that if that field is blank, access shouldn't be reading that
line since it is the else part of the statement. I put a toggle point on the
the first line and access tells me that Me.Vendor = Null and Null = Null.
Whats going on here? Simple syntax error?
Try
If IsNull(me.VendorID) Then...

Dec 8 '06 #2

P: n/a
"Jimmy" <no**@none.comwrote in
news:w0********************@fe02.news.easynews.com :
If Me.Vendor = Null Then

I seems to me that if that field is blank, access shouldn't be
reading that line since it is the else part of the statement.
I put a toggle point on the the first line and access tells me
that Me.Vendor = Null and Null = Null. Whats going on here?
Simple syntax error?
The issue is that nulls never equal anything, not even other nulls.
so null = null can never be true. You have to use a special
function to test if something is null, the IsNull() function.
instead of testing for equality.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.