Re: Dynamically populating Combo Box .?
- From: "Chubbly Geezer" <chubbly_geezer@xxxxxxxxxxxxxxxx>
- Date: Fri, 12 Aug 2005 10:03:43 +0100
Cheers Doug
but not sure I explained clearly the problem..
Because I do not always want to filter my select statement on the the same
field (fields) I need to also store the variable name in the SQL table.
So
"Select * From Transactions Where AccNo = '" & strAccNo & "'"
could just as easily be
"Select * From Transactions Where Surname = '" & strSurname & "'"
or even
"Select * From Transactions Where AccNo = '" & strAccNo & "' and Surname =
'" & strSurname & "'"
In the last example therefore I would save the following text within my SQL
field (strAccNo and strSurname are both variables within my VB app)
"Select * From Transactions Where AccNo = '" & strAccNo & "' and Surname =
'" & strSurname & "'"
but when grabbed by my VB app, I want it to work as
"Select * From Transactions Where AccNo = X1234567 and Surname = Smith"
Code example below:
Sub PopulatecbBox()
......Code to open ADO recordset
With myRecordset
SetUpCombo(cbArg1, .Fields("Arg1cbSelect").Value,
..Fields("Arg1cbField").Value)
End With
End Sub
Private Sub SetUpCombo(ByVal cbComboBox As ComboBox, ByVal strSelect As
String, ByVal strField As String)
Dim oleConn As New System.Data.OleDb.OleDbConnection(strConnADO)
Dim oleAdapter As New System.Data.OleDb.OleDbDataAdapter()
Dim myDataset As DataSet
Dim intCounter As Integer
myDataset = New DataSet()
oleAdapter.SelectCommand = New System.Data.OleDb.OleDbCommand(strSelect,
oleConn)
oleAdapter.Fill(myDataset)
For intCounter = 0 To myDataset.Tables(0).Rows.Count - 1
cbComboBox.Items.Add(myDataset.Tables(0).Rows(intCounter).Item(strField))
Next
End Sub
In this instance strSelect is being passed in as
"Select * From Transactions Where AccNo = '" & strAccNo & "'"
and so obviously my combo box is not being populated.
Cheers
"Doug Bell" <PoorSupport@xxxxxxxxxxxxxxxx> wrote in message
news:OiPzlutnFHA.3304@xxxxxxxxxxxxxxxxxxxxxxx
> Hi Chubbly,
> What you have:
> "Select * From Transactions Where AccNo = '" & strAccNo & "'"
>
> Will (if strAccNo="X5235982") send:
> Select * From Transactions Where AccNo = 'X5235982 '
>
> You can test this by:
> st=
> "Select * From Transactions Where AccNo = '" & strAccNo & "'"
>
> console.writeline (st)
> and looking at the output window.
>
> Some databases prefer double quotes.
> Some need an end character ";"
>
> Doug
>
> "Chubbly Geezer" <chubbly_geezer@xxxxxxxxxxxxxxxx> wrote in message
> news:OzhMnXonFHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
>> I am trying to populate a combo box on a form based on the contents of a
>> field within SQL.
>>
>> i.e.
>>
>> I read the data from the SQL field. In this case I return the string
>> "Select * From Transactions"
>> I populate my dataset and set the dataset as the datasource of my combo
> box.
>> This works fine.
>>
>> However what I want to do is to use a where clause in my select statement
>> such as "Select * From Transactions Where AccNo = '" & strAccNo & "'",
> where
>> strAccNo is a variable within my VB app.
>> Now not surprisingly my combo box is empty as the the datasource is
> exactly
>> as my select statement reads and it is trying to return records where
> AccNo
>> matches strAccNo and not as I had hoped which is to match AccNo to the
>> contents of strAccNo (X5235982 for example).
>>
>> What I have:
>> Select * From Transactions Where AccNo = 'strAccNo'
>>
>> What I want:
>> Select * From Transactions Where AccNo = 'X5235982 '
>>
>> Any ideas appreciated.
>>
>>
>
>
.
- Follow-Ups:
- Re: Dynamically populating Combo Box .?
- From: Chubbly Geezer
- Re: Dynamically populating Combo Box .?
- References:
- Dynamically populating Combo Box .?
- From: Chubbly Geezer
- Re: Dynamically populating Combo Box .?
- From: Doug Bell
- Dynamically populating Combo Box .?
- Prev by Date: Re: Dynamically populating Combo Box .?
- Next by Date: Re: Dynamically populating Combo Box .?
- Previous by thread: Re: Dynamically populating Combo Box .?
- Next by thread: Re: Dynamically populating Combo Box .?
- Index(es):
Relevant Pages
|