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

not in list error...

Status
Not open for further replies.

mjonson

Technical User
Mar 9, 2004
128
GB
hi,
i get a variable undefined error highlighting the top row of my code - can ne1 see why?

Code:
Private Sub taskcombo_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset

 DoCmd.SetWarnings (warningsoff)
 If MsgBox("OK to add new Task type.?. Or Press Cancel to Discard", vbOKCancel + vbwarning, "Add Equip Type?") = vbOK Then
        Set Db = CurrentDb
        Set Rs = Db.OpenRecordset("tbl_task", dbOpenDynaset)
  '     On Error Resume Next
        Rs.AddNew
            Rs![task] = NewData
        
        Rs.Update
        
        Set Db = Nothing
        ' Continue without displaying default error message.
        Response = acDataErrAdded
    Else
    DoCmd.SetWarnings (warningsoff)
    Response = acDataErrContinue
        Me.Undo
    
        If Err Then
            MsgBox "An error occurred. Please try again."
            Response = acDataErrContinue
        Else
            Response = acDataErrAdded
        End If
        Me!taskcombo.Requery
   End If
End Sub
 
How are ya mjonson . . . . .

[blue]DoCmd.SetWarnings [purple]False[/purple]
DoCmd.SetWarnings [purple]True[/purple][/blue]

Calvin.gif
See Ya! . . . . . .
 
hey aceman

thanks fo the tip but no gud - the top line is the only one highlighted
 
mjonson . . . . .

Only the top line usually indicates a compile error at runtime. So it could be anywhere it the code. [blue]The error message is an indication though.[/blue] (I missed the access 97 post).

[purple]vbwarning[/purple] certainly didn't compile! It should've come out as
[purple]vbWarning[/purple] if it truely exist as an constant. Remove/correct/change it. . . .

If it still doesn't work (it should), goto the routine and compile. See whats highlighted . . .

Calvin.gif
See Ya! . . . . . .
 
DoCmd.SetWarnings (warningsoff)???

Dim warningsoff As Boolean

somewhere should do. And...you don't need parantheses

Another option (not recommendable though): remove the line Option Explicit from the top of the module.


HTH


[pipe]
Daniel Vlas
Systems Consultant

 
danvlas said:
remove the line Option Explicit
Why are you suggesting that ?
Happily you said it's not recommendable ...
 
OK, something like Which Option Explicit are you talking about ? ...
 
Okydoky:
To use a variable ONLY after you have declared it, you mention Option Explicit at the top of the module (right beneath Option Compare Database). If you do include this statement and you attempt to use the variable name in the code, you will get a compilation error: Variable Not Defined.
On the contrary, if you need to use a variable without declaring it first, the line must be removed.

Since the poster mentions such an error, I assume the line is at the top of the module.

And TheAceMan1 is right, there is one more unknown variable in the code: vbwarnings, which should probably be vbInformation, vbExclamation or vbCritical

To find the un-defined variable, open any module, go to Debug-Compile. It will highlight the errors.

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
How are ya danvlas . . . . .

The point of the matter is that removing [purple]Option Explicit[/purple] [blue]will not clear the error[/blue], as we have [blue]two unknown/undefined constants[/blue] here. Namely:

[purple](warningsoff)[/purple] & [purple]vbwarning[/purple].

At the very least [blue]mjonson [/blue] needs to replace [purple]vbwarning[/purple] with a valid intrinsic constant (as suggested) and affirm SetWarnings properly . . . [blue]DoCmd.SetWarnings[/blue] [purple]False[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top