View Full Version : why is this not working?


keyur
06-22-2004, 09:23 AM
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

KenHigg
06-22-2004, 09:31 AM
Did you try putting the 'dbOpenDynaset' back in...

keyur
06-22-2004, 09:55 AM
Yes i did, i tried almost all the types.

Thanks again.

KenHigg
06-22-2004, 09:59 AM
I know this isn't going to help but I would take out the new line underscore to get all on one line...

keyur
06-22-2004, 10:09 AM
right, it didnt worked. but thanks neways

KenHigg
06-22-2004, 10:24 AM
And 'Employee List' is a valid table or query name?

keyur
06-22-2004, 11:39 AM
yupe, it's a valid table name.
do i have to reference any library other than Microsoft DAO 3.6 Object Library?

Mile-O
06-23-2004, 01:57 AM
DAO.Database
DAO.Recordset

cable
06-23-2004, 03:40 AM
Set dbsNorthwind = OpenDatabase("Northwind.mdb")

wouldn't you need the full path to the northwind.mdb file in there?

Mile-O
06-23-2004, 03:41 AM
wouldn't you need the full path to the northwind.mdb file in there?

lol, that's true. :)

KenHigg
06-23-2004, 04:13 AM
Did that fix it?

keyur
06-23-2004, 11:58 AM
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
06-23-2004, 12:50 PM
Set db = CurrentDb

cable
06-24-2004, 12:48 AM
Set db = CurrentDb
more exactly:
Set dbsNorthwind = currentdb

at least I think thats what rich meant:)

Rich
06-24-2004, 12:58 AM
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

keyur
06-24-2004, 06:45 AM
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??

KenHigg
06-24-2004, 07:33 AM
Q. Do you have any ADO stuff that works? (I'm not being a smart_ss)

Can you copy and modifiy it to work?

keyur
06-24-2004, 08:01 AM
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

KenHigg
06-24-2004, 08:12 AM
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...

keyur
06-24-2004, 08:25 AM
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.

KenHigg
06-24-2004, 08:34 AM
Cool, glad it's working. I would go with ADO since it's the latest. I've heard it may also be dated (what ain't these days). Either way, it real powerfull because you can programatically get to your data...