Hello, let me explain my problem.
I have two forms. The first form contains text boxes and a datagrid that are bound controls to an ADO recordset. I want users to be able to pull up a second form that allows them to select an integer, hit "OK" and have all of the bound controls be initialized with a recordset that is built off of this integer passed as an argument to the sub: BuildRS.
I can get everything to work except for the binding of the fields. If I ask for a field of the rs recordset, it returns the correct value, but I cannot get it to bind to the text boxes on frmMain. I've tried all of the subs in modules, I can connect to the database, build the recordset, but I can't bind the fields. If I call the BindFields() sub from another form it doesn't work, if I call it from frmMain it works fine.
Consider the following:
--------------------------------
frmMain
Public WithEvents rs As ADODB.Recordset
'I've also tried declaring this public in a .bas module
'(without WithEvents).
Public Sub ConnectDB(fileName As String)
'Code the sets up connection to database
'This works fine in a .bas module or in frmMain.
End Sub
Public Sub BuildRS(Data As Integer)
'Code that executes SQL select to build RecordSet.
'This works fine in a .bas module or in frmMain.
End Sub
Public Sub BindFields()
'Code that binds textbox and datagrid fields on frmMain to
'rs. This works if placed in frmMain, but it must be
'called from frmMain, it doesn't work if called externally,
'and it doesn't work in .bas module even if the text
'controls are called with the frmMain.etc.
Set datagrid.datasource = rs
End Sub
---------------------------
frmSecond
'Another form that is executed by a menu command. User
'selects a number which corresponds to data they wish to
'retrieve. This number is passed to BuildRS to build the
'recordset.
Sub cmdOK_Click()
Dim Selection As Integer
Selection = "1"
Call BuildRS(Selection) 'Works fine
Call BindFields() 'Doesn't work
Unload Me
End Sub
---------------------------
So the crux of the problem is I need a second form to be able to call the subs that build the recordset and bind the fields.
Thank you for any assistance.
Regards.
I have two forms. The first form contains text boxes and a datagrid that are bound controls to an ADO recordset. I want users to be able to pull up a second form that allows them to select an integer, hit "OK" and have all of the bound controls be initialized with a recordset that is built off of this integer passed as an argument to the sub: BuildRS.
I can get everything to work except for the binding of the fields. If I ask for a field of the rs recordset, it returns the correct value, but I cannot get it to bind to the text boxes on frmMain. I've tried all of the subs in modules, I can connect to the database, build the recordset, but I can't bind the fields. If I call the BindFields() sub from another form it doesn't work, if I call it from frmMain it works fine.
Consider the following:
--------------------------------
frmMain
Public WithEvents rs As ADODB.Recordset
'I've also tried declaring this public in a .bas module
'(without WithEvents).
Public Sub ConnectDB(fileName As String)
'Code the sets up connection to database
'This works fine in a .bas module or in frmMain.
End Sub
Public Sub BuildRS(Data As Integer)
'Code that executes SQL select to build RecordSet.
'This works fine in a .bas module or in frmMain.
End Sub
Public Sub BindFields()
'Code that binds textbox and datagrid fields on frmMain to
'rs. This works if placed in frmMain, but it must be
'called from frmMain, it doesn't work if called externally,
'and it doesn't work in .bas module even if the text
'controls are called with the frmMain.etc.
Set datagrid.datasource = rs
End Sub
---------------------------
frmSecond
'Another form that is executed by a menu command. User
'selects a number which corresponds to data they wish to
'retrieve. This number is passed to BuildRS to build the
'recordset.
Sub cmdOK_Click()
Dim Selection As Integer
Selection = "1"
Call BuildRS(Selection) 'Works fine
Call BindFields() 'Doesn't work
Unload Me
End Sub
---------------------------
So the crux of the problem is I need a second form to be able to call the subs that build the recordset and bind the fields.
Thank you for any assistance.
Regards.