Recordset and subroutine

J

Janez Banez

What am I doing wrong in the next code? Using ADODB I am
opening a recordset of a table and with the subroutine I
am wanting to get the values of some fields. I have
defined first my own object (type) for the values of the
fields of one record.

Debuging I found out that the problem must be somehow in
transfering of the references of object variables rst and
vrst as arguments to the subroutine. Call statement cause
the error "Compile error: Object required". Please, help!

Janez

The code:

------------------------
Type tvrst
date1 As Date
num1 As Double
str1 As String
End Type
-------------------------
Public Function Main()

Dim rst As ADODB.Recordset
Dim vrst As tvrst

Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Source = "tblTable1"
rst.LockType = adLockOptimistic
rst.CursorType = adOpenKeyset
rst.Open

Call ReadTable(rst, vrst)
.....
End Function
-------------------------
Public Sub ReadTable(rst As ADODB.Recordset, vrst As tvrst)

vrst.date1 = rst.Fields("DATE1")
.....

End Sub
--------------------------
 
J

janez banez

Debuging further I found that variable vrst.date1 in my
subroutine is somehow "read only". When I put the statement

vrst.date1 = rst.Fields("DATE1")

in the main function before calling the subroutine, it was
precessed without errors and after I put the statement

Debug.Print vrst.date1

as the first statement in the subroutine, this variable
was printed in the Immediate window.

How to make object vrst "non read only" ?

Sincerely Janez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top