Field name

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hi!

How can show a field name in a box from a SQL Statment?

For exemple: "Select Stock, price from Inventory"

I would like a field box to show me the first item I have asked in the SQL
statment (STOCK)

I don't know how to use the "FieldName" property in VBA

Thanks

JS
 
John,
Try this:

Sub test()
Dim dbs As DAO.database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "Select Stock, price from Inventory"
Set qdf = dbs.CreateQueryDef(, sqltext:=strSQL)
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
If rst.EOF = False Then
me.textbox0.value=rst.Fields("Stock"}
End If
End Sub

Geof
 
Back
Top