Solved

Query combo box from another combo box result in vb express

Posted on 2014-07-23
2
248 Views
Last Modified: 2014-07-25
Trying to query a combobox from another combobox result in vb express.  Getting an error near "=" on the select ProductCode query - makes no sense to me as i can't see any obvious error.  

 Private Sub GetMachine()
        'Query product code table
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboMachine.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT Machine FROM tbl_MachineList")
        MsgBox(SQL.recordcount)
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboMachine.Items.Add(r("Machine")) 'machine column
            Next
            '      cboMachine.SelectedIndex = 0 'set combo box on 1st record
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub GetProductCode(Machine As String)
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        'Run query
        SQL.RunQuery("SELECT ProductCode FROM tbl_ProductStandards" & _
>>                               "WHERE Machine = '" & cboMachine.Text & "' ")                      << This line
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboProductCode.Items.Add(r("ProductCode")) 'product code column
            Next
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub cboMachine_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboMachine.SelectedIndexChanged
        GetProductCode(cboMachine.Text)
    End Sub
0
Comment
Question by:SweetingA
2 Comments
 

Author Comment

by:SweetingA
ID: 40215855
OK sorted it out somehow....

    Private Sub GetMachine()
        'Query product code table
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboMachine.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT Machine FROM tbl_MachineList")
        MsgBox(SQL.recordcount)
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboMachine.Items.Add(r("Machine")) 'machine column
            Next
            '      cboMachine.SelectedIndex = 0 'set combo box on 1st record
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub GetProductCode()
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboProductCode.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT ProductCode FROM tbl_ProductStandards WHERE Machine ='" & cboMachine.Text & "' ")
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboProductCode.Items.Add(r("ProductCode")) 'product code column
            Next
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub cboMachine_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboMachine.SelectedIndexChanged
        GetProductCode()
    End Sub
0
 
LVL 15

Accepted Solution

by:
JimFive earned 500 total points
ID: 40217095
The issue was that you didn't have a space before the WHERE.  I always like to put my SQL statements into a string variable and then echo the variable to make sure that I'm getting the statement that I expect.  Missing spaces and quotes are usual culprits.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now