ADODB Recordset - pull fields into variables

C

Clayman

I am trying to pull the results of an SQL query into a series of variables.
When I execute the code, I get various "Not Defined" errors regarding the
format of my assignment.

Here's my SQL:
sSQL = "SELECT EmpData.[FirstName], EmpData.[LastName],
EmpData.[HireDate], " & _
"CurrentData.[VacRate] FROM EmpData, CurrentData WHERE
EmpData.[FileNumber] = " & _
StrFileNum & " AND CurrentData.[FileNumber] = " & StrFileNum & ";"
Set VacRS = VacConn.Execute(sSQL)

If I use:
StrFirstName = VacRS!(EmpData.[FirstName])
Excel will turn FirstName into firstname and tell me EmpData is not defined.

If I use:
StrFirstName = VacRS!([FirstName])
Excel will turn FirstName into firstname and tell me Type-declaration
character does not match declared data type (with VacRS highlighted).

If I use:
StrFirstName = VacRS!(FirstName)
Excel turns FirstName into firstname and tells me it is not defined.

Funny thing though:
StrLastName = VacRS!(LastName)
works without a problem.

I have checked, and the word FirstName is only used in the SQL, the
assignment to StrFirstName and in the word StrFirstName itself.

Ideas?
 
C

Clayman

aw crap. Part of the problem was:
Dim StrFirstame As String
Notice the missing "N" between "First" and "ame"...

Once I found that, I made the following change:
StrFirstName = VacRS![FirstName]

and it worked.

I wanna be a singer in a rock and roll band...
 

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