Passing Strings to function (SELF SOLVED DOH!)
Hello All and thank you in advance.
I am attempting to pass 3 string values to a function to automate filling a series of combo boxes on a form based off of information stored on several tables within a database..
This is the Call:
VB Code:
FillForm("AcolumnName","AtableName","ComboBoxtoFill")
The problem is the Underlined Item within code.
I am not sure of how to translate the Comboboxname from a string to an object im assuming.
I HAVE already attempted to pass the value as an object "
.......,ByVal cboBox As Object.....
But still recived an error at said location but no underline appeard on cbobox in code. So again im stumped. Eventualy there will be 5 or 6 calls to use this function on the Form.
VB Code:
Private Function FillForm(ByVal [B]column[/B] As String, ByVal [B]table[/B] As String, ByVal [B]cbobox[/B] As String)
Dim myconn As SqlConnection
Dim mycmd As SqlCommand
Dim myread As SqlDataReader
Dim output As String
Dim outputInt As String
myconn = New SqlConnection (Bla,Bla,Bla)
myconn.Open()
mycmd = myconn.CreateCommand()
mycmd.CommandText = ("select " & [B]column[/B] & " from " & [B]table[/B])
myread = mycmd.ExecuteReader()
While myread.Read()
output = output & myread.GetString(0)
[U][B]cbobox[/B].[/U]Items.Add(output)
output = ""
End While
myread.Close()
myconn.Close()
cboLocation.SelectedIndex = 1
End Function
Re: Passing Strings to function (SELF SOLVED DOH!)
Bold shows Changes.
Removing Quotes from cbolocation REALLY HELPS, Self DOHHH!!!
VB Code:
FillForm("PLocation", "Location", [B]cboLocation[/B])
VB Code:
Private Function FillForm(ByVal column As String, ByVal table As String, ByVal cbobox As [B]Object[/B])
Dim myconn As SqlConnection
Dim mycmd As SqlCommand
Dim myread As SqlDataReader
Dim output As String
Dim outputInt As String
myconn = New SqlConnection (Bla,Bla,Bla)
myconn.Open()
mycmd = myconn.CreateCommand()
mycmd.CommandText = ("select " & column & " from " & table)
myread = mycmd.ExecuteReader()
While myread.Read()
output = output & myread.GetString(0)
cbobox.Items.Add(output)
output = ""
End While
myread.Close()
myconn.Close()
cboLocation.SelectedIndex = 1
End Function
Re: Passing Strings to function (SELF SOLVED DOH!)
Actualy it would be better if you dclared it as an actual combobox, not as an object.
Tg
Re: Passing Strings to function (SELF SOLVED DOH!)
Even Better THANX!!! :thumb: