Adding Records to a Table (1 Viewer)

saross

Registered User.
Local time
Today, 16:33
Joined
Mar 4, 2003
Messages
120
I've used code compiled from other threads I've read to create a sub that adds a single record onto a table, using the values in the current form to populate the two fields. However, I get an 'Type Mismatch' error message returned and it highlights the Set Recordset line as the problem. Can anyone help and explain why?

CODE:

Private Sub Command60_Click()

Dim db As Database
Dim rsUsers As Recordset
Dim intResponse As Integer

Set db = CurrentDb()
Set rsUsers = db.OpenRecordset("TblSubscriptionUser", dbOpenTable, dbAppendOnly)

rsUsers.AddNew
rsUsers("SubscriptionID") = Me.txtContactID
rsUsers("ContactID") = Me.SelectedSubscriptionID
rsUsers.Update
rsUsers.Close

intResponse = MsgBox("New User Added", vbOKOnly, "Enter New Subscription User")

End Sub

I'm running Windows 2k on XP

:confused:
 

Mile-O

Back once again...
Local time
Today, 16:33
Joined
Dec 10, 2002
Messages
11,316
1. Open a module;
2. Goto Tools -> References;
3. Search the list for Microsoft Data Access Objects 3.6 and check the box for it;
4. Move thr priority of aforementioned library above Microsoft ActiveX Data Objects

That should now work. So that you know you are working with DAO, you should change the following two lines in your code:


Code:
Dim db As Database 
Dim rsUsers As Recordset

to

Code:
Dim db As DAO.Database 
Dim rsUsers As DAO.Recordset
 

saross

Registered User.
Local time
Today, 16:33
Joined
Mar 4, 2003
Messages
120
:eek:
Thanks. I guess I'll get the hang of this eventually...!!
 

Mile-O

Back once again...
Local time
Today, 16:33
Joined
Dec 10, 2002
Messages
11,316
If you are using Access 2000, as you say, then you'll probably find it worthwhile to learn the ADO method rather han DAO as ADO is the way forward and is supported by Access 2000 and above while DAO is on the way out - the last Access which explicitly focused on DAO was Access '97.
 

Users who are viewing this thread

Top Bottom