Solved

Using Checkbox to Update Access DB with VB 2005

Posted on 2006-10-26
4
232 Views
Last Modified: 2010-04-23
Hi

I have an Access DB with a field called Office2003 - Data Type Yes\No.

I have a form in VB 2005 with a Checkbox called CBOffice2003.

When this is checked on the form I would like the DB to be updated.  I have tried as you can see below but I recieve the error:

Data type mismatch in criteria expression.
from
command.ExecuteNonQuery()

Private Sub SaveRecord()

        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\ITAssets.mdb")

        Dim sql As String = String.Empty
        Dim sql1 As String = String.Empty

        If _assetID = 0 Then

            sql = "INSERT INTO tblAssets (EFCRef,Type,Manufacturer,[User],Department,[Model],SerialNo)" & "VALUES('" & cboEFCRef.Text & "', '" & cboType.Text & "','" & cboManufacturer.Text & "','" & cboUser.Text & "','" & cboDepartment.Text & "','" & cboModel.Text & "','" & txtSerialNo.Text & "')"
            sql1 = "UPDATE tblEFCTAGS SET IsUsed = True WHERE EFCTAG='" & cboEFCRef.Text & "'"
        Else

            sql = "UPDATE tblAssets SET EFCRef ='" & cboEFCRef.Text & "'," & "Type='" & cboType.Text & "', Manufacturer='" & cboManufacturer.Text & "',[User]='" & cboUser.Text & "',Department='" & cboDepartment.Text & "',[Model]='" & cboModel.Text & "',SerialNo='" & txtSerialNo.Text & "',Office2003='" & CBOffice2003.Checked & "' WHERE assetID=" & _assetID
            sql1 = "UPDATE tblEFCTAGS SET IsUsed = True WHERE EFCTAG='" & cboEFCRef.Text & "'"

        End If

        conn.Open()

        Dim command As New OleDbCommand(sql, conn)
        Dim command1 As New OleDbCommand(sql1, conn)
        command.ExecuteNonQuery()
        command1.ExecuteNonQuery()


        conn.Close()

        Me.Close()

    End Sub

Thanks
0
Comment
Question by:weight01
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17811536
"Type" is a reserved word in Access.  Try sticking it in square brackets.

Roger
0
 
LVL 1

Author Comment

by:weight01
ID: 17811803
No did not work

Everything worked fine until I added the checkbox - CBOffice2003.

If I remove - ,Office2003='" & CBOffice2003.Checked & "' from the UPDATE string it works fine.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 17812061
Sorry, missed that.  CBOffice2003.Checked returns a Boolean, not a string, so it does not need single quotes around it.

Roger
0
 
LVL 1

Author Comment

by:weight01
ID: 17812112
That worked fine Roger.

Your help is appreciated.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

805 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