Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What I am trying to do is query a specific field for a specific value. If the field value and input value are equal then I want another field updated from True to False within that same row where the "equal" match was found.

Also,

This is called upon with a button_click event.

What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim connStr As String
    connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Tech\LoanerTracking.accdb"

    Dim objConn As New OleDbConnection(connStr)

    Dim str As String
    str = "Select AssetBarcode from TrackingInfo Where (AssetBarcode=TextBox3 AND CheckedOut=True);"

    Dim chg As String
    chg = "Select CheckedOut from TrackingInfo where AssetBarcode=TextBox3"

    Dim cmd As OleDbCommand = New OleDbCommand(str)

    cmd.Connection = objConn

    objConn.Open()

    Try
        If str = TextBox3.Text Then
            chg = False

        End If

        objConn.Close()

        MsgBox("Item Successfully Checked-In")

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    TextBox3.Text = String.Empty
    TextBox2.Text = String.Empty
    TextBox1.Text = String.Empty

End Sub
Posted
Updated 6-Jun-17 2:48am
Comments
Richard MacCutchan 6-Jun-17 3:56am    
What is the problem?
KD209 6-Jun-17 11:22am    
Hi Richard,

Richard provided the solution I was looking for.

1 solution

How have you forgotten how to execute a query and pass a parameter since yesterday[^]?!
VB.NET
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Tech\LoanerTracking.accdb"
    Using conn As New OleDbConnection(connStr)
 
        Dim query As String = "Update TrackingInfo Set CheckedOut = 0 WHERE AssetBarcode = ? And CheckedOut = 1"
        Using cmd As New OleDbCommand(query, conn)
            cmd.Parameters.AddWithValue("?", TextBox3.Text)
            
            Try
                conn.Open()
                cmd.ExecuteNonQuery()
                MsgBox("Item Successfully Checked-In")
                
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Using
    End Using
    
    TextBox3.Text = String.Empty
    TextBox2.Text = String.Empty
    TextBox1.Text = String.Empty
End Sub
 
Share this answer
 
Comments
KD209 6-Jun-17 11:21am    
Hi Richard,

I am trying to relearn all of this as it has been 18 years since I have done it last. Thank you for your help! You code does exactly what I was looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900