A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Set rst = dbs.OpenRecordset(strSql)



 
 
Thread Tools Display Modes
  #1  
Old December 10th, 2008, 11:44 PM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Set rst = dbs.OpenRecordset(strSql)

I have used this switchboad for about a year now, but when I linked my table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)

I know I could build my own switchboard but I really like like this
Microsoft version. Any suggestions?
************************************************** **********
Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.

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].Visible = True
Me![Command1].Enabled = True
Me![Command1].SetFocus
With Me![OptionLabel1]
.Visible = True
.FontWeight = conFontWeightBold
End With
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Me("OptionLabel" & intOption).FontWeight = conFontWeightNormal
Me("Command" & intOption).Enabled = 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("OptionLabel" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
Me("Command" & rst![ItemNumber]).Enabled = True
rst.MoveNext
Wend
End If

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

End Sub
  #2  
Old December 11th, 2008, 01:24 AM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Set rst = dbs.OpenRecordset(strSql)

See whether changing

Dim rst As Recordset

to

Dim rst As DAO.Recordset

makes any difference.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard" wrote in message
...
I have used this switchboad for about a year now, but when I linked my
table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)

I know I could build my own switchboard but I really like like this
Microsoft version. Any suggestions?
************************************************** **********
Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.

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].Visible = True
Me![Command1].Enabled = True
Me![Command1].SetFocus
With Me![OptionLabel1]
.Visible = True
.FontWeight = conFontWeightBold
End With
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Me("OptionLabel" & intOption).FontWeight = conFontWeightNormal
Me("Command" & intOption).Enabled = 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("OptionLabel" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
Me("Command" & rst![ItemNumber]).Enabled = True
rst.MoveNext
Wend
End If

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

End Sub



  #3  
Old December 11th, 2008, 01:39 AM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Set rst = dbs.OpenRecordset(strSql)

Thanks Doug I will try that.

"Douglas J. Steele" wrote:

See whether changing

Dim rst As Recordset

to

Dim rst As DAO.Recordset

makes any difference.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard" wrote in message
...
I have used this switchboad for about a year now, but when I linked my
table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)

I know I could build my own switchboard but I really like like this
Microsoft version. Any suggestions?
************************************************** **********
Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.

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].Visible = True
Me![Command1].Enabled = True
Me![Command1].SetFocus
With Me![OptionLabel1]
.Visible = True
.FontWeight = conFontWeightBold
End With
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Me("OptionLabel" & intOption).FontWeight = conFontWeightNormal
Me("Command" & intOption).Enabled = 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("OptionLabel" & rst![ItemNumber]).Visible = True
Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
Me("Command" & rst![ItemNumber]).Enabled = True
rst.MoveNext
Wend
End If

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

End Sub




  #4  
Old December 11th, 2008, 12:16 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Set rst = dbs.OpenRecordset(strSql)

Try changing the line to the following and see if that helps

Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Richard wrote:
I have used this switchboad for about a year now, but when I linked my table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)

  #5  
Old December 11th, 2008, 11:06 PM posted to microsoft.public.access.gettingstarted
Richard
external usenet poster
 
Posts: 1,419
Default Set rst = dbs.OpenRecordset(strSql)

Hi Guys,

Tried both of your solutions with no luck. I will keep at it and see if I
can't rework this code a bit.

Thank you Doug and John.


"John Spencer" wrote:

Try changing the line to the following and see if that helps

Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Richard wrote:
I have used this switchboad for about a year now, but when I linked my table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)


  #6  
Old December 12th, 2008, 07:21 AM posted to microsoft.public.access.gettingstarted
[email protected]
external usenet poster
 
Posts: 130
Default Set rst = dbs.OpenRecordset(strSql)

On Dec 11, 12:44*am, Richard
wrote:
I have used this switchboad for about a year now, but when I linked my table
to the SQL server with OBDC, the code highlighted on this spot.

Set rst = dbs.OpenRecordset(strSql)

* *I know I could build my own switchboard but I really like like this
Microsoft version. Any suggestions?
************************************************** **********
Private Sub FillOptions()
' Fill in the options for this switchboard page.

* * ' The number of buttons on the form.

* * 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].Visible = True
* * Me![Command1].Enabled = True
* * Me![Command1].SetFocus
* * With Me![OptionLabel1]
* * * * .Visible = True
* * * * .FontWeight = conFontWeightBold
* * End With
* * For intOption = 2 To conNumButtons
* * * * Me("Option" & intOption).Visible = False
* * * * Me("OptionLabel" & intOption).Visible = False
* * * * Me("OptionLabel" & intOption).FontWeight = conFontWeightNormal
* * * * Me("Command" & intOption).Enabled = 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("OptionLabel" & rst![ItemNumber]).Visible = True
* * * * * * Me("OptionLabel" & rst![ItemNumber]).Caption = rst![ItemText]
* * * * * * Me("Command" & rst![ItemNumber]).Enabled = True
* * * * * * rst.MoveNext
* * * * Wend
* * End If

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

End Sub


Do you got any error message?

Regards,
Branislav Mihaljev
Microsoft Access MVP
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:41 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.