Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

null/empty string ifStatement in recordset

Status
Not open for further replies.

Earth

Technical User
May 8, 2000
59
0
0
AU
Hi,

A fairly simple (I think) question:

I have a form, with a button on it that opens a word document and fills in some (bookmark) fields on it. That all works nicely. The problem is, I am attempting to get certain bookmarks filled in with information from different db fields depending on the information stored in certain fields. More specifically:

The database is opened, an SQL statement is created, and the recordset is created as such....

Set rsMidbase1 = dbMidbase.OpenRecordset(sSql)
' [in the recordset, a field called "Add2" exists.]
' this is now the bit that doesn't work:

If rsMidbase1![Add2] = "Null" Then
objDoc.Bookmarks("Add2").Range.text = rsMidbase1![Suburb] & " " & rsMidbase1![State] & " " & rsMidbase1![Country] & " " & rsMidbase1![PCode]

Else
objDoc.Bookmarks("Add2").Range.text = rsMidbase1![Add2]
objDoc.Bookmarks("Add3").Range.text = rsMidbase1![Suburb] & " " & rsMidbase1![State] & " " & rsMidbase1![Country] & " " & rsMidbase1![PCode]
End If

The intention is: if the "Add2" Field has 'stuff', then to fill it into the "Add2" bookmark, and put the "Add3" field information into the "Add3" bookmark. This works fine.
If the "Add2" Field is Null, then the "Add3" field information (which will never be null) should be put in the "Add2" bookmark, and the "Add3" bookmark left blank. The problem is: in a case where the "Add2" field is null, the "Else" Branch of the If statement is still exectued, and on the first line of it,
----> Run-time error '94': Invalid use of null.
error message occurs.

Is the rsMidbase1![Add2] = "Null" bit not doing as I plan?

Please help. [sig][/sig]
 
If isnull(rsMidbase1![Add2]) Then

or

If Len(rsMidbase1![Add2] & "") = 0 Then

[sig]<p>Keith C Taylor<br><a href=mailto:TekTips@kctaylor.co.uk>TekTips@kctaylor.co.uk</a><br><a href= Information Gardener</a><br>The C stands for Computer![/sig]
 
That worked perfectly. Thanks Keith. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top