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

Coding a switchboard

Status
Not open for further replies.

extrhman

Programmer
Feb 6, 2004
10
US
I am in the process of making changes to DB that was designed by some one else. I currently had to add a report to the DB and inserted a new button on a switchboard to run this, i used the switchboard manager to do this. My button is in the switchboard items table, yet when I switch to that paticular switchboard I recieve an error...I am fairly new to this and have never written code for a switchboard before. Does anyone know what my problem is? Here is the code and where it seems to be locking up...by the way there are only 5 buttons on this switchboard so i know it hasn't reached the maximum allowed.

Private Sub FillOptions()
' Fill in the options for this switchboard page.
' AI-06/10/2003, AI-08/19/2003
' The number of buttons on the form.
Const conNumButtons = 10

Dim con As Object
Dim rs As Object
Dim stSql 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 con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True 'This is where it hangs
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
If rs!ItemText = "E&xit Program" Then
Me("OptionLabel" & rs!ItemNumber).ForeColor = 16711680
Me("OptionLabel" & rs!ItemNumber).FontBold = True
ElseIf rs!ItemText = "&Return to Main Menu" Then
Me("OptionLabel" & rs!ItemNumber).ForeColor = 0
Me("OptionLabel" & rs!ItemNumber).FontBold = True
Else
Me("OptionLabel" & rs!ItemNumber).ForeColor = 0
End If
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub
 
Found the problem myself...just turned out to be that the Access switchboard manager Auto numbers the new buttons and the number it gave my new button (11) was higher then the # of buttons allowed on the form (10)...I just had to change this value in the switchboard items table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top