Desperately need MVP help

L

Lisa

Below is the code I have on an afterupdate event on a cbo
box on a control. My computer FREEZES at the set db =
currentdb statement.

I have done this type of thing in another XP database and
it was fine.

I did write the code in Access 2000 and it worked fine
there, but when I opened it in Access XP it froze up.

HELP. What am I missing?

I have the following references checked:
Visual Basic for Applications
Microsoft Access 10.0 Object Library
Microsoft DAO 3.6 Object Library
OLE Automation
Microsoft Visual Basic for Applications Extensibility 5.3

Dim db As Database
Dim rec As Recordset

Set db = CurrentDb
Set rec = db.OpenRecordset("qryExistingContact",
dbOpenSnapshot)
With rec
If rec.RecordCount <> 0 Then
MsgBox "This contact and addresscode already exist in the
database." & _
"Please Select the Existing Contact from the list."
SendKeys "{esc}"
rec.Close
Exit Sub
Else
rec.Close
End If
End With

Thank You
Lisa
 
L

Lisa

Nevermind
I discovered I can't use the variable db in XP....

Works just fine in 2000, in fact the Smith/Sussman book
Beginning Access 2000 vba book taught me that variable.

How special!
Lisa
 
N

Newbie

I have used the following in an XP database without any problem

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Table1")
 
D

Dirk Goldgar

Lisa said:
Nevermind
I discovered I can't use the variable db in XP....

Works just fine in 2000, in fact the Smith/Sussman book
Beginning Access 2000 vba book taught me that variable.

How special!

Nonsense. There is nothing wrong with using code like

Dim db As Database
Set db = CurrentDb

in Access 2002. Of course, you do have to have a reference set to the
DAO 3.6 object library, and it won't work in an ADP because an ADP *has*
no "current database", only a current connection. I think you're
jumping to conclusions about what was wrong.
 
L

Lisa

Hmmmm....isnt' that strange.

I retyped the code in Access 2002 using the dbsDatabase
instead of db and it worked - so I assumed the db was the
problem.

I just went back in and changed the dbsDatabase back to db
and it worked this time.

Could it have something to do with the fact that I typed
the original code in Access 2000?
It worked fine in 2000, but not when I opened it in XP.

Oh well, all's well that end's well...my code works again.
Lisa
 
D

Dirk Goldgar

Lisa said:
Hmmmm....isnt' that strange.

I retyped the code in Access 2002 using the dbsDatabase
instead of db and it worked - so I assumed the db was the
problem.

I just went back in and changed the dbsDatabase back to db
and it worked this time.

Could it have something to do with the fact that I typed
the original code in Access 2000?
It worked fine in 2000, but not when I opened it in XP.

Puzzling. I suppose you may have had a broken reference which was
subsequently fixed, but I really can't guess what else could have been
the problem without knowing the exact sequence of events.
Oh well, all's well that end's well...my code works again.

That is, after all, the main point. But I wouldn't want you to go
forward with the idea that there's something wrong with "db" as a
variable name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top