Compile error in a sub when converting to 2002

J

Jacqueline

Users are getting a compile error in their mdb since
converting. (they aren't sure what it was created in but
I'm guessing Access 97).
Here is the sub that the debugger stops on the 1st line...
Dim dbs as Database...

Can someone please have a look at this and see what has to
be changed in order for this sub to work in 2002?

Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.
Const conNumButtons = 8

Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the
focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set dbs = CurrentDb()
strSQL = "SELECT * FROM [Switchboard Items]"
strSQL = strSQL & " WHERE [ItemNumber] > 0 AND
[SwitchboardID]=" & Me![SwitchboardID]
strSQL = strSQL & " ORDER BY [ItemNumber];"
Set rst = dbs.OpenRecordset(strSQL)

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with
the items.
If (rst.EOF) Then
Me![OptionLabel1].Caption = "There are no items
for this switchboard page"
Else
While (Not (rst.EOF))
Me("Option" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Visible =
True
Me("OptionLabel" & rst![ItemNumber]).Caption =
rst![ItemText]
rst.MoveNext
Wend
End If

' Close the recordset and the database.
rst.Close
dbs.Close

End Sub
 
J

Jacqueline

Thanks...I was looking into changing that but the subs in
this database aren't inside a module (therefore Tools-
Reference button is disabled)...so how can I open the
reference library?

When the VB window opens to debug the switchboard form I
get the sub on that form (I can see all the other subs and
functions)...I tried creating a new module and cutting all
the subs and functions into that and changing the
reference but then when I try to recreate the event
procedures on the form I can't find the sub??
Make any sense??

-----Original Message-----
Access 2002 databases don't have a reference to the DAO library by default.
Details:
http://users.bigpond.net.au/abrowne1/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to the newsgroup. (Email address has spurious "_SpamTrap")

Jacqueline said:
Users are getting a compile error in their mdb since
converting. (they aren't sure what it was created in but
I'm guessing Access 97).
Here is the sub that the debugger stops on the 1st line...
Dim dbs as Database...

Can someone please have a look at this and see what has to
be changed in order for this sub to work in 2002?

Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.
Const conNumButtons = 8

Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the
focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set dbs = CurrentDb()
strSQL = "SELECT * FROM [Switchboard Items]"
strSQL = strSQL & " WHERE [ItemNumber] > 0 AND
[SwitchboardID]=" & Me![SwitchboardID]
strSQL = strSQL & " ORDER BY [ItemNumber];"
Set rst = dbs.OpenRecordset(strSQL)

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with
the items.
If (rst.EOF) Then
Me![OptionLabel1].Caption = "There are no items
for this switchboard page"
Else
While (Not (rst.EOF))
Me("Option" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst! [ItemNumber]).Visible =
True
Me("OptionLabel" & rst! [ItemNumber]).Caption =
rst![ItemText]
rst.MoveNext
Wend
End If

' Close the recordset and the database.
rst.Close
dbs.Close

End Sub


.
 

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