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

ADO recordset to variable

Status
Not open for further replies.

Tim2525

Technical User
Feb 7, 2005
51
0
0
US
Hi All,

Trying to load a result from a query to a variable - currRate. When I get to code line "currRate = objRec.GetString(adClipString, ColumnDelimeter:=" ", RowDelimeter:=vbCrLf)", I get the following error.

Run-time error '3021':
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

The table only has one row in it - a currency rate.

Any help would be most appreciated.

Code:
    Dim strSQL As String
    Dim currRate As Currency
    Dim objRec As ADODB.Recordset
    
    strSQL = "SELECT rate FROM qryCurrentRate;"

    Set objRec = New ADODB.Recordset

    objRec.Open strSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
    
    currRate = objRec.GetString(adClipString, ColumnDelimeter:=" ", RowDelimeter:=vbCrLf)
    
    MsgBox (currRate)

    objRec.Close
    
    Set objRec = Nothing

TIA,

Tim
 
try DLOOKUP( "Rate", "qryCurrentRate")

this will return the rate.

or,

currRate = objRec!Rate

this will return the value in the field.
 
Thanks for the reply stix4t2

I'm wanting to learn the ADO part so I tried your suggestion and I'm getting "0" zero return. I did notice my sql statement was completely off. I modified it and still getting zero returned.

Any ideas?

Code:
    strSQL = "SELECT rate FROM tblRate;"

    Set objRec = New ADODB.Recordset

    objRec.Open strSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
    
    currRate = objRec!Rate
    
    MsgBox (currRate)

    objRec.Close

TIA,
Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top