Set SourceObject using a string in VBA
Good day all. I have an issue that you might be able to help me with. I've searched the forum and have tried several suggestions that I thought were similar to my issue, but they did not work...leaving me to believe that my issue is either unique, of I've simply done something wrong from the start.
I have a form that has a ComboBox (cboFieldTableList), a SubForm (fsubFieldDataEditor), and a button (btnProcess). The ComboBox is displaying a simple text list from a table, and there is VB code that matches the text in the combobox with a corresponding query. What I'd like to happen is for the subform to display the correct query information when the button is clicked based on what is selected in the combobox. Below is a copy of my code. I get the compile error on this line:
Any suggestions how I can get this to work? Thank you in advance for your time and expertise!
Good day all. I have an issue that you might be able to help me with. I've searched the forum and have tried several suggestions that I thought were similar to my issue, but they did not work...leaving me to believe that my issue is either unique, of I've simply done something wrong from the start.
I have a form that has a ComboBox (cboFieldTableList), a SubForm (fsubFieldDataEditor), and a button (btnProcess). The ComboBox is displaying a simple text list from a table, and there is VB code that matches the text in the combobox with a corresponding query. What I'd like to happen is for the subform to display the correct query information when the button is clicked based on what is selected in the combobox. Below is a copy of my code. I get the compile error on this line:
Code:
Me!fsubFieldDataEditor.Form.SourceObject = strForm
Any suggestions how I can get this to work? Thank you in advance for your time and expertise!
Code:
Private Sub Form_Load()
' Wipes the subform clean upon form load
Me.fsubFieldDataEditor.SourceObject = ""
End Sub
Private Sub btnProcess_Click()
Dim strForm As String
If Me.cboFieldTableList = "Change Type" Then
strForm = "qryFIELD_ChangeType"
ElseIf Me.cboFieldTableList = "Description" Then
strForm = "qryFIELD_Description"
Else: MsgBox "Please make a selection from the list."
Exit Sub
End If
Me!fsubFieldDataEditor.Form.SourceObject = strForm
Me!fsubFieldDataEditor.Requery
End Sub
Last edited: