Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2005

Tip: Looking for answers? Try searching our database.

Run-Time error '91'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don - 08 May 2005 23:42 GMT
I am trying to get code to work that identifies error messages so I can
suppress certain messages. Using the following code, I get a Run-Time error
'91' Object variable or With block veriable not set. The offending line of
code is:

If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then

and entire code is as follows:

Private Sub Command8_Click()

  Dim dbs As DAO.Database
   Dim wrk As DAO.Workspace
   Dim strSQL As String, strQuery As String, strMessage As String

   strSQL = "UPDATE tblTimerDate SET LastTimerDate = " & _
           Format(Date, "\#mm/dd/yyyy\#")
   
   On Error GoTo Err_Handler

   If Time() > #6:30:00 AM# Then

       If DLookup("LastTimerDate", "tblTimerDate") < Date Then
       
           Set wrk = DAO.DBEngine.Workspaces(0)
           Set dbs = CurrentDb
           
           ' begin transaction
           wrk.BeginTrans
       
           ' Appends Rx table to RX1 table "Adds new RX's to RX1 table"
           strQuery = "1Append Rx to RX1 Query"
           dbs.Execute strQuery ', dbFailOnError
           ' Append Patient table to Patients table "Adds new records"
           strQuery = "2Append Patient to PatientsQuery"
           dbs.Execute strQuery ', dbFailOnError
           ' Deletes records from Patients that are "GONE" over 1 year
           strQuery = "3Delete >1 years From Patients qry"
           dbs.Execute strQuery ', dbFailOnError
           ' Update Housing Units from Patient table to Patients table
           strQuery = "4Update Housing from Patient to Patients"
           dbs.Execute strQuery ', dbFailOnError
           ' Deletes records from RX1 that are "GONE" over 1 year
           strQuery = "5RX1 Delete >1 years Query"
           dbs.Execute strQuery ', dbFailOnError
       
          ' Update tblTimerDate table
          strQuery = "embedded SQL to update tblTimerDate"
          dbs.Execute strSQL ', dbFailOnError
       
           ' no error so commit transaction
           wrk.CommitTrans
   
       End If
   End If
   
Exit_Here:
   Exit Sub
   
Err_Handler:
   If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
       dbs.Execute strQuery
       Resume Next
   Else
       strMessage = Error & " (" & Err.Number & ")" & vbNewLine & vbNewLine
& _
           "(Error in " & strQuery & ")" & _
           vbNewLine & vbNewLine & "Transaction rolled back and no tables
updated."
       MsgBox strMessage, vbExclamation, "Error"
   
       wrk.Rollback
   End If
   Resume Exit_Here

End Sub

I think I should Set strQuery to something but not sure what?

Thanks,

Dennis
Douglas J. Steele - 09 May 2005 00:35 GMT
Has dbs been instantiated when the error occurs? Does strQuery have a value?

It may be that your error is occurring before either of those is true. If
so, try nesting the two If statements, rather than Anding them together:

If Err.Number = 3022 Then
  If dbs.QueryDefs(strQuery).Type = dbQAppend Then
        dbs.Execute strQuery
       Resume Next
  End If
Else
  strMessage = Error & " (" & Err.Number & ")" & vbNewLine & vbNewLine & _
     "(Error in " & strQuery & ")" & _
     vbNewLine & vbNewLine & "Transaction rolled back and no tables
updated."
   MsgBox strMessage, vbExclamation, "Error"
   wrk.Rollback
End If

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I am trying to get code to work that identifies error messages so I can
> suppress certain messages. Using the following code, I get a Run-Time
[quoted text clipped - 80 lines]
>
> Dennis
Don - 09 May 2005 01:17 GMT
Douglas,

I made the nesting change you suggested and it corrected the 91 error. But
it looks like I have an additional issue.

I now get a Access error ("The database has been placed in a state by user
'Admin' on machine 'Computer' that prevents it from being opened or locked.
(3734)

(Error in)
Transaction rolled back and not tables updated.)

I then get a (Run-Time error '3034'

You tried to commit or rollback a transaction without first beginning a
transaction.)

Debug gives this line of code:
wrk.Rollback

In my original post I did begin a transaction:

' begin transaction
 wrk.BeginTrans

This is confusing can you take a look at the original code?

Thanks,
Dennis

> Has dbs been instantiated when the error occurs? Does strQuery have a value?
>
[quoted text clipped - 99 lines]
> >
> > Dennis
Don - 09 May 2005 01:41 GMT
Douglas,

I think my last post:

I now get a Access error ("The database has been placed in a state by user
'Admin' on machine 'Computer' that prevents it from being opened or locked.
(3734) (Error in) Transaction rolled back and not tables updated.)

is what I was trying to get with the code to identify errors so I could add
code to ignore some errors and maybe as a result, I get the Run-Time error
'3034'? Example of code I would use to ignore errors below:

If Err.Number = 3022 Then
   If dbs.QueryDefs(strQuery).Type = dbQAppend Then
        dbs.Execute strQuery
       Resume Next
  End If

   If Err.Number = 3734 Then
   If dbs.QueryDefs(strQuery).Type = dbQAppend Then
        dbs.Execute strQuery
       Resume Next
  End If

But now when I run the code with these changes, it does not run or give an
error message. The following is the code with the changes: Note that I have
commented out some code to save it but not run as I am just trying to
identify error codes at this time.

Private Sub Command8_Click()

  Dim dbs As DAO.Database
   Dim wrk As DAO.Workspace
   Dim strSQL As String, strQuery As String, strMessage As String

   strSQL = "UPDATE tblTimerDate SET LastTimerDate = " & _
           Format(Date, "\#mm/dd/yyyy\#")
   
   On Error GoTo Err_Handler

   If Time() > #6:30:00 AM# Then

       If DLookup("LastTimerDate", "tblTimerDate") < Date Then
       
           Set wrk = DAO.DBEngine.Workspaces(0)
           Set dbs = CurrentDb
           
           
           ' begin transaction
           wrk.BeginTrans
       
           ' Appends Rx table to RX1 table "Adds new RX's to RX1 table"
           strQuery = "1Append Rx to RX1 Query"
           dbs.Execute strQuery ', dbFailOnError
           ' Append Patient table to Patients table "Adds new records"
           strQuery = "2Append Patient to PatientsQuery"
           dbs.Execute strQuery ', dbFailOnError
           ' Deletes records from Patients that are "GONE" over 1 year
           strQuery = "3Delete >1 years From Patients qry"
           dbs.Execute strQuery ', dbFailOnError
           ' Update Housing Units from Patient table to Patients table
           strQuery = "4Update Housing from Patient to Patients"
           dbs.Execute strQuery ', dbFailOnError
           ' Deletes records from RX1 that are "GONE" over 1 year
           strQuery = "5RX1 Delete >1 years Query"
           dbs.Execute strQuery ', dbFailOnError
       
          ' Update tblTimerDate table
          strQuery = "embedded SQL to update tblTimerDate"
          dbs.Execute strSQL ', dbFailOnError
       
           ' no error so commit transaction
           wrk.CommitTrans
   
       End If
   End If
   
Exit_Here:
   Exit Sub
   
Err_Handler:
   
   
   
   
   If Err.Number = 3022 Then
   If dbs.QueryDefs(strQuery).Type = dbQAppend Then
        dbs.Execute strQuery
       Resume Next
  End If

   If Err.Number = 3734 Then
   If dbs.QueryDefs(strQuery).Type = dbQAppend Then
        dbs.Execute strQuery
       Resume Next
  End If

Else
  strMessage = Error & " (" & Err.Number & ")" & vbNewLine & vbNewLine & _
     "(Error in " & strQuery & ")" & _
     vbNewLine & vbNewLine & "Transaction rolled back and no tables updated."
   MsgBox strMessage, vbExclamation, "Error"
   wrk.Rollback
End If

   ' The below code is
   'If Err.Number = 3022 And dbs.QueryDefs(strQuery).Type = dbQAppend Then
       'dbs.Execute strQuery
       'Resume Next
   'Else
       'strMessage = Error & " (" & Err.Number & ")" & vbNewLine &
vbNewLine & _
           '"(Error in " & strQuery & ")" & _
           'vbNewLine & vbNewLine & "Transaction rolled back and no tables
updated."
       'MsgBox strMessage, vbExclamation, "Error"
   
       'wrk.Rollback
   End If
   Resume Exit_Here

End Sub

What do you think?

Thanks,
Dennis

> Douglas,
>
[quoted text clipped - 129 lines]
> > >
> > > Dennis
Douglas J. Steele - 09 May 2005 02:00 GMT
Can you determine what line of code is causing the error? Try
single-stepping through the code.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Douglas,
>
[quoted text clipped - 273 lines]
>> > >
>> > > Dennis
Don - 09 May 2005 03:34 GMT
Douglas,
I am not sure what you mean. I have tried the Debug step into and Run to
Cursor and found that I get no action after doing both on each line except a
message when Run to Cursor, is run, on lines without an exacutable the
message "Line is not an exacutable statement" is reported. Are you referring
to something else? I know you can single step a macro but I do not know how
to single step code? How do you do that?

Thanks,
Dennis

> Can you determine what line of code is causing the error? Try
> single-stepping through the code.
[quoted text clipped - 276 lines]
> >> > >
> >> > > Dennis
Douglas J. Steele - 09 May 2005 22:40 GMT
F8 (Step Into) repeatedly lets you run code line by line.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Douglas,
> I am not sure what you mean. I have tried the Debug step into and Run to
[quoted text clipped - 302 lines]
>> >> > >
>> >> > > Dennis
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.