Hi Everyone,
I'm doing a stock Control System as a school Project using An Access 2007 DB and Visual Studio 2010. I'm trying to do an update Query based on two variables entered into comboboxes, I cannot get the VB to accept the conditions for this, Can anyone Help me?
Here is my Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "AND" & "'" ComboBox3.Text & "'"
        Dim cmd As New OleDbCommand
        con.Open()
        cmd = New OleDbCommand(Query, con)
        cmd.ExecuteNonQuery()
        MsgBox("Stock Updated Successfully", MsgBoxStyle.Information)
        cmd.Dispose()
        con.Close()
        ComboBox2.Text = ""
        ComboBox3.Text = ""
        TextBox2.Text = ""
    End Sub

I Cannot get the Code to recognise the Last "'", is there a way to do this?

Many Thanks

Ziggy

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "AND" & "'" ComboBox3.Text & "'"

Missing Other Column Name :

"AND OtherColumName = " & "'" ComboBox3.Text & "'"

Edited 4 Years Ago by Jx_Man: n/a

Are you getting a syntax error? I think it is because you aren't using the WHERE clause correctly. You need to have:

WHERE Laminate = '" & ComboBox2.Text & "'" & "AND WHERE <another column> = " & "'" ComboBox3.Text & "'"

By missing that second column you are saying "WHERE laminate = some_text AND some_other_text.

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"

I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"

hello !
use this

"update Prod_DB_Completed_Board set Stock Level = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and Board Size = '" & ComboBox3.Text & "'"

It will work fine :) if your prob is solved please mark this thread solved :)

Regards

M.Waqas Aslam

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"

I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"

No need to add the where twice

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and  [Board Size] = '" & ComboBox3.Text & "'"

This will help u

Thank you very much M.Waqas Aslam, thats fixed the problem for me :)

This question has already been answered. Start a new discussion instead.