Compile Error: Variable not defined

G

Guest

Does anyone know how I can correct this line of VB code that worked in Access97 but is giving a compile error in Access 2000 XP version? I am trying to open the Switchboard items. Please let me know if you need more of my code.

Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)

The compile error states that dbOpenDynaset variable not defined.

Here is part of the code:

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8

' An error that is special cased.
Const conErrDoCmdCancelled = 2501



Dim dbs As Object
Set dbs = CurrentDb

Dim rst As Object
Set rst = Recordset

' Dim db As Object
' Set db = dbOpenDynaset
' Dim dbOpenDynaset As Object
' Dim db As AcOpenDataMode


On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)
rst.FindFirst "[SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn

' If no item matches, report the error and exit the function.
If (rst.NoMatch) Then
MsgBox "There was an error reading the Switchboard Items table."
rst.Close
dbs.Close
Exit Function
End If





I also want to mask the password when users type it in. Here are few codes I have tried. They did not work. Any suggestion will be helpful.

Private Sub Form_Open(Cancel As Integer)
Dim pword As String
Yourname = InputBox("In order to help manage updates, your name will be recorded along with the time. Data entry info can be viewed under the MISC tab. Please provide your name. Data Entry by...")
If Yourname = "" Then DoCmd.Close: Exit Sub
pword = InputBox("Enter the password...")
'Set pword.SetValue = "Password"
'Set pword = "Password" (OBJECT required)
'Set InputMask = "Password" (InputMask is now a variable not defined)
'Set InputBox.InputMask = "####" DID NOT WORK
'Set pword.InputMask = "####" DID NOT WORK
'example for VB InputMask Forms!Customers!Telephone.InputMask = "(###) ###-####"

If Cancel Then DoCmd.Close
'If pword = "zero" Then Set InputBox.InputMask = "####"
'If pword = "zero" Then Set InputBox = "****"'
'If pword = "zero" Then Set InputBox.InputMask SetValue = "****" '
If pword <> "zero" Then DoCmd.Close
End Sub
 
D

Douglas J. Steele

The problem is that "Recordset" is an object in both the ADO and DAO models.
By default, Access 97 only had a reference to DAO, but Access 2003 has
references to both, and the ADO reference is higher than the DAO, which
means it gets precedence.

If you're not going to be using ADO, open the References dialog (with any
code module open, select Tools | References from the menu bar) and uncheck
the reference to Microsoft ActiveX Data Objects 2.1 Library

If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rst as DAO.Recordset (to guarantee an ADO recordset, you'd use Dim
rst As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



LizPratt said:
Does anyone know how I can correct this line of VB code that worked in
Access97 but is giving a compile error in Access 2000 XP version? I am
trying to open the Switchboard items. Please let me know if you need more
of my code.
Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)

The compile error states that dbOpenDynaset variable not defined.

Here is part of the code:

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8

' An error that is special cased.
Const conErrDoCmdCancelled = 2501



Dim dbs As Object
Set dbs = CurrentDb

Dim rst As Object
Set rst = Recordset

' Dim db As Object
' Set db = dbOpenDynaset
' Dim dbOpenDynaset As Object
' Dim db As AcOpenDataMode


On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)
rst.FindFirst "[SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn

' If no item matches, report the error and exit the function.
If (rst.NoMatch) Then
MsgBox "There was an error reading the Switchboard Items table."
rst.Close
dbs.Close
Exit Function
End If





I also want to mask the password when users type it in. Here are few
codes I have tried. They did not work. Any suggestion will be helpful.
Private Sub Form_Open(Cancel As Integer)
Dim pword As String
Yourname = InputBox("In order to help manage updates, your name
will be recorded along with the time. Data entry info can be viewed under
the MISC tab. Please provide your name. Data Entry by...")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top