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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Debugging???

Status
Not open for further replies.

jane30

Programmer
Nov 14, 2000
92
US
The following is my code to set up timerinterval property. But Access 97 returned me an error message: "Invalid use of Me keyword."

Private Sub Timer(TimerInt As Integer)
On Error GoTo Timer_Err

Dim db As Database

Set db = CurrentDb
Set TimerInt = Me.TimerInterval

DoCmd.SetWarnings False
DoCmd.OpenForm ("test")

If TimerInt = 3000 Then
DoCmd....
Else
If TimerInt = 4000 Then
docmd....
Else
If TimerInt = 6000 Then
DoCmd....
End If
End If
End If

DoCmd.SetWarnings True

End Sub

What's wrong with my code? Thank you very much
 
Jane,

Please try to be more clear in your questions, OK? Here are a few of my thoughts reviewing your code....

Code:
Private Sub Timer(TimerInt As Integer)

 
    'Label Timer_Err is not found in this routine
    On Error GoTo Timer_Err

    'Un-Necessary, as 'db' is never referenced after set
    'It MAY be one source or ERROR if ADO is in use
    Dim db As Database

    'Again, this is un-necessary as it ("db" is never referenced
    Set db = CurrentDb

    'If Option Explicit is set, then "TimerInt" must be defined.  sinec it is NOT
    'defined in this procedure, it must either be a form level variable
    'or the cause of (yet another) error.  This APPEARS to be the first
    'problem / ERROR found (re your statement ( ... invalid use of "ME" ... )
    
    'You do not state WHERE the procedure is located, however two statements later,
    'you "open" a form "test".  If form 'Test' is the location of the timer of
    'interest - and this code is elsewhere (e.g. a general module), then 'test'
    'is not in context at the execution of the statement.  "ME" can only refer to
    'THE current form.
    Set TimerInt = Me.TimerInterval

    'This PREVENTS you from geting the error message - which MIGHT
    'give you a CLUE re the (NEXT) error source.
    DoCmd.SetWarnings False

    'As noted above, if form 'Test' is the home of the timer of interest
    'it is NOT in scope until after the execution of the followin statement
    'and thus doesn't refer to a valid form.
    DoCmd.OpenForm ("test")

     'POOR procedure follows.

'    If (TimerInt = 3000) Then
''        DoCmd ....
'     Else
'        If (TimerInt = 4000) Then
''            DoCmd ....
'         Else
'            If (TimerInt = 6000) Then
''                DoCmd ....
'            End If
'        End If
'    End If
'______________________________End POOR Procedure


'________________________________A "BETTER" Procedure
    Select Case Me.TimerInterval
        Case Is = 3000
            'DoCmd ... "A"
        Case 4000
            'DoCmd ... "B"
        Case 6000
            'DoCmd ... "C"
        Case Else
            'Do whatever else may be useful
    End Select

    DoCmd.SetWarnings True

End Sub
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top