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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recordset help? 2

Status
Not open for further replies.

jamesmills

Technical User
Jul 30, 2003
43
0
0
GB
can anyone tell me why this is not working?
i am new to this recordset business!

i am sure i have this correct?
it says there is a synax error in the query expression

Dim currentServerType As String
Dim currentServerNumber As String
Dim serverIP As String

currentServerType = controlPanelType.Value
currentServerNumber = serverNumber.Value

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT serverIP FROM tblServerList WHERE serverType = " & currentServerType & " AND serverName = " & currentServerNumber & ";")
serverIP = rs("serverIP")
rs.Close
 
I would suggest the following:

dim sSQL AS String to capture your SQL for clarity

sSQL = "SELECT serverIP FROM tblServerList WHERE serverType = " & currentServerType & " AND serverName = " & currentServerNumber & ";")

set rs = CurrentDb.OpenRecordset(sSQL)

serverIP = rs.fields(0)

rs.fields(0) holds the record returned from the recordset which is only one field the serverIP

Hope this helps.

Shazam
 
ok so i changed my code to what you said!

I am still getting a run-time error 3075

It says synta error (missing operator) in query expression 'serverType = Plesk AND serverName = Server 3'.

Whats going on?
There is a tbl called tblServerList and there are heading called serverType and serverNumber

Thanks
 
Hi jamesmills,

You need some quotes to tell it that Plesk is a literal.

Code:
Set rs = CurrentDb.OpenRecordset("SELECT serverIP FROM tblServerList WHERE serverType =
Code:
'
Code:
" & currentServerType & "
Code:
'
Code:
 AND serverName = " & currentServerNumber & ";")


Enjoy,
Tony
 
amazing!

it did not work at first, but after adding the '' around both of them and not just the first one it works!

Could you explain this, thanks
 
Hi jamesmills,

My mistake. You need quotes around all your non-numeric literals.

I didn't read your post closely enough and saw the CurrentServerNumber as 3 rather than as "Server 3". Assuming it to be numeric, I didn't put it in quotes. You did and you were right.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top