Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RunTime Error 91

Status
Not open for further replies.

redbay

Technical User
Joined
Oct 13, 2003
Messages
145
Location
GB
I have a timer on my form that refreshes records and notifies another user that a record has been added. recently i have been getting a runtime error 91 - object variable with block variable not set, why would this have started to happen. This is the code i am using and the error is on the line ** at each end

Private Sub Form_Timer()
'This procedure uses functions from the Windows API.
'The declarations for these procedures are found in the Module
'within this database and documented on the Microsoft Windows
'Programming site.

'FindWindow, GetForegroundWindow, SetForegroundWindow, Sleep

Dim intNew As Long
Dim hwnd As Long
Dim hwndCur As Long
Dim intLoop As Integer
Dim retval As Long

**intcount = Forms("frmTracker").Recordset.RecordCount**
Forms("frmTracker").Requery
intNew = Me.Recordset.RecordCount

hwnd = FindWindow(vbNullString, "frmTracker")
hwndCur = GetForegroundWindow()

If (intcount <> intNew) And (hwnd <> hwndCur) Then

SetForegroundWindow hwnd
Forms(&quot;frmTracker&quot;).Recordset.MoveLast
intcount = Forms(&quot;frmTracker&quot;).Recordset.RecordCount
For intLoop = 1 To 5
Beep
Sleep 5000



Next intLoop
End If

End Sub
 
It does not work, because
a) either frmTracker is not opened or
b) the code is within frmTracker itself.

You can work around this by using the DCount function for the respective underlying query.

Hope this helps,
MakeItSo
 
Thanks for your response

frmTracker is open and the code is on that form, where should i put the DCount?
 
can anyone help a bit more on this please as i am still stuck, i have tried adding some error handling code but it isnt happy with it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top