Runtime error 91

S

SF

Hi

I have the following code for updating SQL Server table connected through
ODBC. Evrytime I run this code, I received a runtime error # 91.



Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Stg As String

Stg = "UPDATE tblProjectActivityNumber SET
tblProjectActivityNumber.Pr_ActivityNumber =" & Me.Pr_ActivityNumber
Stg = Stg & " WHERE (((tblProjectActivityNumber.Pr_ObjectID)=" &
Me.ProjectName & "));"

dbs.Execute Stg, dbFailOnError + dbSeeChanges
 
T

Tom Wickerath

In the Immediate Window, we can see that error 91 returns the following:

?error(91)
Object variable or With block variable not set

The reason you are getting this error is that you have declared dbs, but you
haven't set it yet. You need to add the following line of code (I recommend
after all the Dim statements):

Set dbs = CurrentDB()

You may also need to include quotes around the Me.ProjectName part, if this
is a text string. Something like this:

" WHERE (((tblProjectActivityNumber.Pr_ObjectID)= ' " & ProjectName & " ' ));"

At the end of your procedure, in an ExitProc section, you should make sure
to set this variable to nothing.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
Top