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

What is this error?

Status
Not open for further replies.

Vec

IS-IT--Management
Jan 29, 2002
418
0
0
US
The code below gives me an error:
"Object Variable or with block variable not set"

and highlights:
Set rsTemp = Data1.Database.OpenRecordset("SELECT SUM(ADD6) AS TOTALPRICE FROM LOG WHERE ORDERNUM > 0", dbOpenDynamic)

Here is the code that causes the error:

Data1.DatabaseName = "data.mdb"
Dim sql As String
Dim dbfields As String
dbfields = "Add6"

sql = ("SELECT " & dbfields & " FROM log WHERE OrderNum > 0")

Data1.RecordSource = sql

Dim rsTemp As Recordset
Set rsTemp = Data1.Database.OpenRecordset("SELECT SUM(ADD6) AS TOTALPRICE FROM LOG WHERE ORDERNUM > 0", dbOpenDynamic)

lbl1.Caption = "$" + CStr(rsTemp!totalprice)

rsTemp.Close
Set rsTemp = Nothing


Am I missing a reference or something? -
radium.gif

Looking Toward The Future
 
It doesn't look like you have actually connected to the database. I don't tend to use the Data Controls but I would imagine that you need to open the database before it can be used.
 
I game him the code Pie... It's from the "How to add up these numbers" thread.

I explained it was a bit iffy, and I've gone though looping through the recordset as an alternative...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top