Home > Software engineering >  The problem of the ACCESS code in the rs. The eof=<object is closed, don't allow operation&g
The problem of the ACCESS code in the rs. The eof=<object is closed, don't allow operation&g

Time:09-24

 Private Sub fillbtns () 
'show in the table of switch box
The number of 'button
Const connumbuttons As Integer=8
Dim the rs As New ADODB. You
Dim STRSQL As String
Dim intbtn As Integer
Me! [r]. Btn1 SetFocus
For intbtn=2 To connumbuttons
Me (" BTN "& amp; Intbtn). The Visible=False
Me (" LBL "& amp; Intbtn). The Visible=False
Next intbtn

'open the switch option table
STRSQL="select * from [switch options table] where [itemnumber]> 0 and switchboardID=me. [switchboardID] order by [itemnumber];"
Set the rs=GetRS (STRSQL)

If (EOF) rs. Then
Me! [lbl1]. Caption="this switch panel page without this option!"
The Else
While (Not (EOF) rs.)
Me (" BTN "& amp; Rs! [itemnumber]). The Visible=True
Me (" LBL "& amp; Rs! [itemnumber]). The Visible=True
Me (" LBL "& amp; Rs! [itemnumber]). The Caption=rs! [itemtext]
Rs. MoveNext
Wend
End the If
'closed data set and database
Rs. Close
Set the rs=Nothing

End Sub

CodePudding user response:

This question I answered a few days ago, don't know if you ask questions, but the problem seems to be the same,
In VB, generally USES the ADO object or ADO control database operation is very simple, easy;
1, it seems that your code didn't see the database connection object, and only the recordset object, database operation must have the ADO database connection object with the recordset object,
Dim cn As New ADODB. Connection 'statement: database Connection object
Dim the RS As New ADODB. You 'statement: Recordset object
Popular said, is to connect to the database, database connection object cn RS recordset objects are connected data table get a recordset,
2, the connection record set must have a database connection object, if the database connection object cn has been connected to the database, so you know the connection of the database:
For example: RS. Open the "Select * From data table name", cn, 2, 2 it is the method of reading data table records (of course can also be RS. Open the "Select * From data table name", cn, 1, 2, but the statement)
For example: RS. Open the "Select * From data table name", cn, 3, 2 it is new, modify the record method
3, in a statement the cn, RS object, unnecessary reload again using the set statements behind these two objects, for example, you set the RS=GetRS (STRSQL) is not right,
4, the Access database connection:
Cn. The Open ". The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ database name. MDB. Persist Security Info=False "
The App. The Path is refers to the root directory of the program,

CodePudding user response:

Can you help me to modify it, please see I sent you my public module 'by the SQL statement returns a string QueryStr reference ADODB library. The object you
The Public Function GetRS (ByVal QueryStr As String) As the ADODB library you
Dim the rs As New ADODB. You
Dim Conn As New ADODB. Connection
On Error GoTo GetRS_Error
Set the Conn=CurrentProject. Connection
Rs. The Open QueryStr, Conn, adOpenKeyset, adLockOptimistic
The Set GetRS=rs
GetRS_Exit:
Set the rs=Nothing
Set the Conn=Nothing
The Exit Function
GetRS_Error:
MsgBox (Err. Description)
Resume GetRS_Exit


End the Function
  •  Tags:  
  • VBA
  • Related