Connecting Tech Pros Worldwide Forums | Help | Site Map

have a value from access table

Newbie
 
Join Date: Aug 2007
Posts: 1
#1: Aug 23 '07
hi

I want to have a value for my table in access database which name Biomed

I use this code

Public Sub test9()
Dim orst As DAO.Recordset
Dim odb As DAO.Database

Dim i As Integer
Set odb = CurrentDb
Set orst = odb.OpenRecordset("select * from biomed where biomedtab = NC5+1159", dbOpenDynaset)



For i = 0 To orst.Fields.Count - 1
MsgBox orst.Fields(i).Value
Next i

orst.Close

odb.Close
Set orst = Nothing
Set odb = Nothing
End Sub

but a have a message error in line set orst and message error is error "3061"

can everbody help me , please?

thanks

Expert
 
Join Date: Aug 2007
Posts: 122
#2: Aug 23 '07

re: have a value from access table


Quote:

Originally Posted by bouanane26

hi

I want to have a value for my table in access database which name Biomed

I use this code

Public Sub test9()
Dim orst As DAO.Recordset
Dim odb As DAO.Database

Dim i As Integer
Set odb = CurrentDb
Set orst = odb.OpenRecordset("select * from biomed where biomedtab = NC5+1159", dbOpenDynaset)



For i = 0 To orst.Fields.Count - 1
MsgBox orst.Fields(i).Value
Next i

orst.Close

odb.Close
Set orst = Nothing
Set odb = Nothing
End Sub

but a have a message error in line set orst and message error is error "3061"

can everbody help me , please?

thanks

you need to put the parameter in either single or double quote marks if it isn't a number, and SQL statements should end with a semicolon, so:

Set orst = odb.OpenRecordset("SELECT * FROM biomed WHERE biomedtab = 'NC5+1159'; ", dbOpenDynaset)
Reply