Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    56

    Red face Unanswered: How to update a table field from a form?

    Hi all,

    I need some assistance on the following (It would be much appreciated!):

    I am trying to create some code behind a command button in a form which will add 1 onto a number in a field (in a table) depending on a condition being met. I am having problems creating the WHERE condition to compare the record ID in the table to the record ID selected on the form.


    +++++++++++++++++
    strSQL = "UPDATE tblTEST "
    strSQL = strSQL & "Set numprod = numprod + 1 & "" """
    strSQL = strSQL & "WHERE prodID = & " Me![prodID]" & ;"
    +++++++++++++++++++

    I know the above is incorrect but its all i have at the moment....

    Any ideas on how to acheive this (Its driving me crazy),

    Cheers,

    Coolowen.

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    have a go with:

    strSQL = "UPDATE tblTEST "
    strSQL = strSQL & "Set numprod = numprod + 1 "
    strSQL = strSQL & "WHERE prodID = " & Me.[prodID] & ";"

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Jan 2003
    Posts
    56
    Hi thanks a million for your suggestion. I solved that problem but I am still unable to get the field to update. Here is what I have:

    Dim strSQL As String

    strSQL = "UPDATE tbltest "
    strSQL = strSQL & "Set numprod = numprod + 1 WHERE prodID = Forms![test]![prodID];"

    DoCmd.RunSQL strSQL

    The numprod field is numerical and I am trying to add on 1 to that number each time the command button is clicked. At present, the sql statement executes but the value never goes to the table. Any ideas?

    coolowen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •