Results 1 to 2 of 2
  1. #1
    orcaa is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2012
    Posts
    19

    Update table after input in form

    I have a table called "T_Plate" with fields "Plate_Name" and "Checkout_Date" and "Checkout" (this is True/False field).
    I have a form "F_update_checkout__Plates" with Textbox called "Text17" and a button called "Command19"

    Now the user can fill in a plateName in "Text17" of the form fi "Plate_20" and push the button. The fields "Checkout_Date" should be updated to current date and "Checkout" should the checkbox be updated to False

    This is the VB code I tried , but get an errormessage . Please some help.


    Private Sub Command19_Click()
    If IsNull(Me!Text17) Then


    MsgBox "You must input a value to PlateName"
    Else
    CurrentDb.Execute "UPDATE T_Plate " & _
    "SET T_plate.Checkout = False" And "Checkout_Date = Date" where T_Plate.Plate_Name = " &forms![F_update_checkout__Plates]![Text17], dbFailOnError"
    End If
    End Sub

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    The date function as well as the form reference cannot be contained within double quotes since they are variables. Also, the dbfailonerror is part of the command, so it must not be enclosed in double quotes. Further, if the Plate_Name field is a text data type you must enclose the text value coming from the form in single quotes. Also, dates must be enclosed by # signs. With that, the correct SQL Update query syntax is as follows:

    "UPDATE T_Plate SET T_plate.Checkout = False And Checkout_Date =#" & Date() & "# where T_Plate.Plate_Name ='" & forms![F_update_checkout__Plates]![Text17] & "'"

    I typically put the query text into a variable and then reference the variable in the CurrentDB.Execute command line

    Dim mySQL as string
    mySQL= "UPDATE T_Plate SET T_plate.Checkout = False And Checkout_Date =#" & Date() & "# where T_Plate.Plate_Name ='" & forms![F_update_checkout__Plates]![Text17] & "'"

    currentDB.execute mySQL, dbfailonerror

    If you put the query text into a variable you can print the text to the Immediate window in VBA (using the debug.print statement) to check for errors. Here is an example of where you might place the debug.print statement


    Dim mySQL as string
    mySQL= "UPDATE T_Plate SET T_plate.Checkout = False And Checkout_Date =#" & Date() & "# where T_Plate.Plate_Name ='" & forms![F_update_checkout__Plates]![Text17] & "'"

    debug.print mySQL

    currentDB.execute mySQL, dbfailonerror

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  2. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  3. Replies: 1
    Last Post: 11-07-2010, 11:04 AM
  4. Update two tables from one input form
    By Jeff-H in forum Forms
    Replies: 7
    Last Post: 09-26-2010, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums