Cant Dim As database?

XaloRichie

Registered User.
Local time
Today, 10:30
Joined
Jul 2, 2003
Messages
70
I am using Access ver2002 from Office Xp professional.
I wanted to dim MyDb As Database but the drop down list does not have (As) Database only data accesspage?

Is there something i need to activate or is there another way of doing this. When I simply type the line:
Dim MyDb As Database I get a compile error " user defined type not defined?

Any ideas.
 
You need to set your references to DAO Object Library 3.6

Open a module, Goto Tools -> References

Find DAO Object Library 3.6 and check the box. Now ensure that its priority is above the ActiveX Data Objects Library.

And, rather than use: Dim db As Database, use Dim db As DAO.Database
 
Excellent

Thanks I had forgotten about those things and was really worried i had a Duff Version :p
 
Hmmmn

Well I did that but now im getting an error 13 type mismatch Any further suggestions.
Heres the code

Public Function AddRecord()
wcustid = 999
Dim Mydab As DAO.Database, MyRecordset As Recordset
Set Mydab = DBEngine.Workspaces(0).Databases(0)

' Open the table as type recordset
Set MyRecordset = Mydab.OpenRecordset("HireDetails", DB_OPEN_TABLE)

'Create new record
MyRecordset.AddNew
MyRecordset("CustomerID") = WCusID
'save record
MyRecordset.Update
'Close able
MyRecordset.Close

End Function
 
MyRecordset As DAO.Recordset too!

As for the type mismatch, I'd guess that the field CustomerID and the variable/object WCusID are of different datatypes. If the ID is a long integer, and WCusID is a control on your form, you might have to use the CLng() function to convert it to the correct type.
 
Well, I've tried what you said but no luck it seems that the vb editor is highlighting the "Set Myrecordset " line in yellow when it reports mismatch type 13:confused:
It has to be a simple error
 
try putting the DIM Recordset statement on a separate line instead of using the comma.
 
Dim Mydab As DAO.Database, MyRecordset As DAO.Recordset
(as Mile-O sugggested - in case you missed it:))
 
Try others

Dim wks As DAO.Workspace
Dim Mydab as DAO.Database
Dim MyRecordset As DAO.Recordset

If the dao is selected, then if it isn't before the ado, it doesn't see it, you must define it. as the above show.


If you are using the current database use
Set db = CurrentDb()
For more help see the DAO to ADO white paper which shows how to accomplish DAO or ADO

DAO to ADO MS WHITEPAPER
 
Not sure

I have tried all of this i think,, here is code but when it runs i get MsgBox "Can't find file 0" ?????
 
No Here is the code

Public Function AddRecord()
Dim Wks As DAO.Workspace

Dim Mydab As DAO.Database
Dim MyRecordset As DAO.Recordset
Set Db = CurrentDb()
Set Mydab = DBEngine.Workspaces(0).OpenDatabase(0)

' Open the table as type recordset
Set MyRecordset = Mydab.OpenRecordset("HireDetails", DB_OPEN_TABLE)
wcustid = Forms![Form1]![Text2]



'Create new record
MyRecordset.AddNew
MyRecordset("CustomerID") = wcustid
MsgBox "Record added"
'save record
MyRecordset.Update
'Close Table
MyRecordset.Close

End Function
 
Re: No Here is the code

Try it like this:
Public Function AddRecord()


Dim Mydab As DAO.Database
Dim MyRecordset As DAO.Recordset
Set MyDab = CurrentDb()


' Open the table as type recordset
Set MyRecordset = Mydab.OpenRecordset("HireDetails",dbOpenTable)
wcustid = Forms![Form1]![Text2]



'Create new record
With Myrecordset
.AddNew
!CustomerID= wcustid
MsgBox "Record added"
'save record
.Update
'Close Table
.Close
End With
End Function
 

Users who are viewing this thread

Back
Top Bottom