-Compile Error: Invalid Qualifier
Hi All
I have written a simple function to populate various combo boxes in my application. The comboboxes are on various seperate forms so i decided to create the function as a public function and i wrote it in a global.bas module (not sure if this was the right thing to do so let me know if you think this should be changed)
Anyway the main problem is that when I pass the combobox_name to the function e.g. "Form1.cboBranchName" i get the invalid qualifier error
For info the sStoredProcName string parameter seems to pass without problem
P.s. My Vb knoweldge is very rusty and isnt great to begin with so please can you break it down a simply as u can, and feel free to point out any other glaring errors ;-)
Code:
The called function
****************************************************
Public Function PopulateComboBoxes(sStoredProcName As String, sComboBox As String, intCol As Integer, bNotSpecified As Boolean)
Dim sqlcon3 As New adodb.Connection
Dim Rs3 As New adodb.Recordset
Dim temp1 As Variant
Dim sqlstr As String
Dim i As Integer
sqlcon3.Open "Provider=sqloledb;data source=szs005;initial catalog=CallLog;", "shoezone", "property"
With Rs3
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
End With
Set Rs3 = sqlcon3.Execute(sStoredProcName)
Rs3.MoveFirst
Do While Not Rs3.EOF
sComboBox.AddItem Rs3.Fields(intCol).Value
sComboBox.ItemData(sComboBox.NewIndex) = Rs3.Fields _(intCol).Value
Rs3.MoveNext
Loop
sComboBox.Text = sComboBox.List(0)
Rs3.Close
sqlcon3.Close
End Function
*****************************************************
The Calling function
******************************************************
Private Sub PopulateFilterBys()
'Get Branch List
Call PopulateComboBoxes("Exec branch", "Form1.cboBranch", 0, True)
End Sub
************************************************************
Hi All
I have written a simple function to populate various combo boxes in my application. The comboboxes are on various seperate forms so i decided to create the function as a public function and i wrote it in a global.bas module (not sure if this was the right thing to do so let me know if you think this should be changed)
Anyway the main problem is that when I pass the combobox_name to the function e.g. "Form1.cboBranchName" i get the invalid qualifier error
For info the sStoredProcName string parameter seems to pass without problem
P.s. My Vb knoweldge is very rusty and isnt great to begin with so please can you break it down a simply as u can, and feel free to point out any other glaring errors ;-)
Code:
The called function
****************************************************
Public Function PopulateComboBoxes(sStoredProcName As String, sComboBox As String, intCol As Integer, bNotSpecified As Boolean)
Dim sqlcon3 As New adodb.Connection
Dim Rs3 As New adodb.Recordset
Dim temp1 As Variant
Dim sqlstr As String
Dim i As Integer
sqlcon3.Open "Provider=sqloledb;data source=szs005;initial catalog=CallLog;", "shoezone", "property"
With Rs3
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
End With
Set Rs3 = sqlcon3.Execute(sStoredProcName)
Rs3.MoveFirst
Do While Not Rs3.EOF
sComboBox.AddItem Rs3.Fields(intCol).Value
sComboBox.ItemData(sComboBox.NewIndex) = Rs3.Fields _(intCol).Value
Rs3.MoveNext
Loop
sComboBox.Text = sComboBox.List(0)
Rs3.Close
sqlcon3.Close
End Function
*****************************************************
The Calling function
******************************************************
Private Sub PopulateFilterBys()
'Get Branch List
Call PopulateComboBoxes("Exec branch", "Form1.cboBranch", 0, True)
End Sub
************************************************************