gateguard
asked on
VBA error: Expected user-defined type, not project.
I'm trying to learn VBA in access and I cut-pasted some sample code from an online book on the subject into my Visual Basic Editor (with my Access database open).
I changed the names in the sample to match my database, but I get this error when I run the code:
Expected user-defined type, not project.
Here's the code:
Sub exaObjectVar()
'Declare some object variables
Dim dbLib As fct
Dim rsFact As Recordset
Dim rsFact2 As Recordset
'Set dbLib to the current database (i.e. fct)
Set dbLib = CurrentDb
'Open a recordset object for the fact table
Set rsFact = dbLib.OpenRecordset("fact" )
'Two object variables will refer to the same object
Set rsFact2 = rsFact
'Use a property of this object
MsgBox "fact record count: " & rsFact.RecordCount
'Destroy the object using rsFact2 reference
rsFact2.Close
'Now rsFact has nothing to refer to, so we get error
MsgBox "fact record count: " & rsFact.RecordCount
End Sub
I changed the names in the sample to match my database, but I get this error when I run the code:
Expected user-defined type, not project.
Here's the code:
Sub exaObjectVar()
'Declare some object variables
Dim dbLib As fct
Dim rsFact As Recordset
Dim rsFact2 As Recordset
'Set dbLib to the current database (i.e. fct)
Set dbLib = CurrentDb
'Open a recordset object for the fact table
Set rsFact = dbLib.OpenRecordset("fact"
'Two object variables will refer to the same object
Set rsFact2 = rsFact
'Use a property of this object
MsgBox "fact record count: " & rsFact.RecordCount
'Destroy the object using rsFact2 reference
rsFact2.Close
'Now rsFact has nothing to refer to, so we get error
MsgBox "fact record count: " & rsFact.RecordCount
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on What version of Access you are running it may not like the Database. You may have to go into the Tools...References Menu and select DAO library. If you have Both ADO and DAO in the project you will have to explicity dim the objects
Dim db as DAO.Database
Dim db as DAO.Database
I am with Arthur:
(what is fct?)
gateguard, some feedaback required.....
(what is fct?)
gateguard, some feedaback required.....
Richie_Simonetti: my guess is that gateguard is VERY new to this and has a database named "fct.mdb". He/she thinks that CurrentDb should be pointed to a variable named fct, to be sure that it points to the correct mdb (of course, this code is writen and is running INSIDE fct.mdb, but clrearly gateguard is VERY confused as to what is going on).
AW
AW
ASKER
fct is the name of my database
I see the syntax error in that line.
I'm going to correct it and try again.
(And it's true, I am confused!)
I see the syntax error in that line.
I'm going to correct it and try again.
(And it's true, I am confused!)
ASKER
that was it
Dim dbLib As fct
to read
Dim dbLib as Database
and see if that helps.
AW