Why this does not work?

giana
12-19-2003, 12:06 PM
This is quite odd for me. The first part of the code populates a combobox on a form from a table in an access db. It works perfectly.
The second part should do the same thing, but in fact it does not and I get an error back of "Invalid use of Null". Also in debug mode I noticed that passing the mouse on the first .EOF sentence the .EOF = true, while the second .EOF = false (and in the following code line is the null error). Anybody knows how??

Set EventRecSet = db.Execute("SELECT EventName from Events")
Do Until EventRecSet.EOF
strEventName = EventRecSet.Fields("EventName") cmbEvents.AddItem strEventName
Set cmbEvents.DataSource = adoPrimaryRS
EventRecSet.MoveNext
Loop

Dim EmplRecSet As Recordset
Dim strEmplName As String
Set EmplRecSet = db.Execute("SELECT Name FROM Employees")
Do Until EmplRecSet.EOF
strEmplName = EmplRecSet.Fields("Name")
cmbEmployee.AddItem strEmplName
Set cmbEmployee.DataSource = adoPrimaryRS
EmplRecSet.MoveNext
Loop

00100b
12-19-2003, 12:24 PM
Put [] around the Name of the Query

Set EmplRecSet = db.Execute("SELECT [Name] FROM Employees")

Name is a reserved word and the brackets tell the query to take what is between it as a field name versus the reserved word.

giana
12-19-2003, 12:28 PM
Put [] around the Name of the Query

Set EmplRecSet = db.Execute("SELECT [Name] FROM Employees")

Name is a reserved word and the brackets tell the query to take what is between it as a field name versus the reserved word.

tx for the reply. I tried, but I am still getting the same error. And anyhow, why would it work without brackets in the first one and not in the second one?

reboot
12-19-2003, 12:29 PM
It isn't Name in the first one, it's EventName

giana
12-19-2003, 12:31 PM
It isn't Name in the first one, it's EventName
I know that, because it's a different table with a different columnname

00100b
12-19-2003, 12:38 PM
Do any of the [Name] fields in the table contain a null value (blank, nada, nothing)? That would cause the error because NULL is not the same as "".
Try


strEmplName = EmplRecSet.Fields("Name") & ""

This will concatenate an empty string to Null making the result an empty string for each instance when [Name] is null.

giana
12-19-2003, 12:44 PM
Do any of the [Name] fields in the table contain a null value (blank, nada, nothing)? That would cause the error because NULL is not the same as "".
Try


strEmplName = EmplRecSet.Fields("Name") & ""

This will concatenate an empty string to Null making the result an empty string for each instance when [Name] is null.

As a matter of fact there was a null value in the table, which I didn't realize. now it works perfectly. thank you so much

giana

Zaph
12-20-2003, 07:25 AM
Name is a reserved word...

Uhm...no it isn't...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum