VB sql to return value

BigJimSlade

Registered User.
Local time
Today, 18:26
Joined
Oct 11, 2000
Messages
173
Hello, Big Jim here:

I was hoping to use VB to run an sql statement and then place the single value returned by the sql statement in a label on a form. Here is the code I was using:

******
Dim rsta As Recordset
Dim strSQL As String
Dim strHold As String

strSQL = "Select [1] From [00Fleet] Where Base ='" & gstrBase & "' AND BoatType ='" & gstrHull & "';"

Set rsta = CurrentDb.OpenRecordset(strSQL)

strHold = rsta.[1]
lblJanFir.Caption = strHold
*****

The line "strHold = rsta.[1]" seems to be causing the problem here. Any ideas? Thanks in advance for your help.


Big Jim
 
Use:

strHold = rsta!1

or:

strHold = rsta("1")

or:

strHold = rsta(1) ' first field, no matter which name
 
Thanks MHM! Your advice wokred great.

If I might ask, why is the difference between using "." and "!" in VB? For example, object properties are referenced using ".", but the recordset is referenced using "!".

Thanks again!

Big Jim
 

Users who are viewing this thread

Back
Top Bottom