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

VBA error

Status
Not open for further replies.

cheeryki

Technical User
Joined
May 14, 2002
Messages
4
Location
HK
When i try to run this program, a error shown i haven't set object variable or with block variable.
Does anyone know what's problem of the following VB code?




Private Sub Command8_Click()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset


Set cnn = CurrentProject.Connection
rst.Open "salesperson", cnn, adOpenKeyset, adLockOptimistic, adCmdTable



rst.MoveFirst
total = 0

Do While Not rst.EOF
total = total + (rst![basic salary] + rst![sales] * rst![commission rate])
rst.MoveNext

Loop
rst.Close
cnn.Close
MsgBox "total amount=" + Str(total)

End Sub
 
It seems that you declare rst object, but do not assign variable to it.

combo
 
Ooops, should be:
It seems that you declare rst variable, but do not assign any object to it.

combo
 
combo~

so how should i do to assign the object?
i am the new user in VBA, can you please help me to corret the code?

many thanks
 
Don't know anything about VBA with Databases, but my guess would be to change:

Dim rst As ADODB.Recordset

to:

Dim rst As New ADODB.Recordset

-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top