why is this not working?

keyur

Registered User.
Local time
Today, 07:59
Joined
Jun 22, 2004
Messages
41
Hi i copied the addnew recordset example from VB Help and changed the names to match my database. i am not sure why it is not working. maybe it's just a small little think but when u dont know it it's so frustrating.

Sub AddNewX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strFirstName As String
Dim strLastName As String

Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)

Sub AddNewX()

Dim dbsdb1 As Database
Dim rstEmployees As Recordset
Dim strFirstName As String
Dim strLastName As String

Set dbsdb1 = OpenDatabase("db1.mdb")

' gives a type mismatch error on the next line.
Set rstEmployees = _
dbsdb1.OpenRecordset("Employee List")


any help would be great
thanks
 
Did you try putting the 'dbOpenDynaset' back in...
 
Yes i did, i tried almost all the types.

Thanks again.
 
I know this isn't going to help but I would take out the new line underscore to get all on one line...
 
right, it didnt worked. but thanks neways
 
And 'Employee List' is a valid table or query name?
 
yupe, it's a valid table name.
do i have to reference any library other than Microsoft DAO 3.6 Object Library?
 
Set dbsNorthwind = OpenDatabase("Northwind.mdb")

wouldn't you need the full path to the northwind.mdb file in there?
 
sorry guys, couldn't reply earlier. now this might be stupid but this code is in the same file itself. so the file is already open and i am trying to reopen it. maybe this is the cause.
 
Rich said:
Set db = CurrentDb
more exactly:
Set dbsNorthwind = currentdb

at least I think thats what rich meant:)
 
cable said:
more exactly:
Set dbsNorthwind = currentdb

at least I think thats what rich meant:)
no it wasn't, as I see it he's not using Northwind at all and just included the code for comparison with his own
 
thanks guys. but it really doesnt solves my first problem. i still get the type mismatch error. Does 'Recordset' and 'Table' means the same thing??
 
Q. Do you have any ADO stuff that works? (I'm not being a smart_ss)

Can you copy and modifiy it to work?
 
First, what's the difference between ADO and DAO. dont worry Ken, i am not.

I tried but it gave me an error that connection not available.

thanks
 
DAO is the older method of accessing recordsets. ADO the newer version. Perhaps I could do you a mini-version of some ADO code and post the entire .mdb. Then you can execute it to see if it works. Sounds like you may have a object reference issue (Access needs to use a file it that it can't find). If you ever get it to work, study the code and fully understand what each line does. Otherwise you'll go bats debugging it...
 
Thank a lot Ken.

But i figured out what the problem was. It was just defining the variable.

I just changed
rstEmployees as Recordset to rstEmployees to DAO.Recordset.
and it works perfect.

Ken, if you already made that file, i will take it :D . It will be a good learning tool for me. is it good to use DAO or ADO??

Thanks a lot everyone.
 

Users who are viewing this thread

Back
Top Bottom