Referencing a cell in an Access table with VB

jeffbruce

Registered User.
Local time
Today, 04:08
Joined
Jun 29, 2007
Messages
19
Let's say I have a Microsoft Access table called tblConstants in my database program (which 'conveniently' has a VB back-end).

How would I go about referencing a specific field of a particular record (and therefore, a specific cell) using VB code?

I am in dire syntax straits here; hopefully a VB expert wouldn't mind lending some expertise in this domain.
 
to get a single field, check out dlookup

dlookup("fieldname","tablename","something to identify the record")
 
I think it would be something like this..I hope i'm not missing anything

Dim strSQL As String
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.Open "Select * from tblConstants"

'for code below 1 is just an example. could be whichever value you want to get to the desired record.
strSQL = "[Fieldname for Unique ID goes here] = " & 1

rst.Find strSQL

'This will hold the value of your specific cell
Dim myvalue as string

myvalue = rst.Fields("FieldName").value
'if you want to display the value in a messagebox
msgbox myvalue


rst.close
set rst = nothing
 
Both of these techniques seem to work. Thanks to both of you -- problem solved.
 

Users who are viewing this thread

Back
Top Bottom