Results 1 to 5 of 5
  1. #1
    TioAdjie is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2014
    Posts
    16

    Update Table dari form

    Dear Access Master,
    I have a problem about updating table from a form.
    I have a table named TableData and want to update the value in TableData from my form named formA with subform named subformB. In my subformB there textbox named Record No and No. I place the cursor on subformB and click the button, it works until msgbox, but doesn't work on the next code. Do you have any idea what's missing in my VBA code ? Thanks,

    Here's my VBA code :

    Private Sub Command104_Click()


    Dim iStartNo As Long
    Dim IStartRecordNo As Long
    Dim IPrevRecordNo As Long

    iStartNo = [Forms]![FormA]![SubformB].[Form]![No]
    IStartRecordNo = [Forms]![FormA]![SubformB].[Form]![RecordNo]
    IPrevRecordNo = IStartRecordNo - 1

    MsgBox ("" & iStartNo & "")
    MsgBox ("" & IStartRecordNo & "")
    MsgBox ("" & IPrevRecordNo & "")

    DoCmd.SetWarnings False
    strSql = "UPDATE TableData SET TableData.RecordNo = '" & IPrevRecordNo & "' WHERE (((TableData.[No])='" & iStartNo & "'));"
    DoCmd.RunSQL strSql
    DoCmd.SetWarnings True
    [Forms]![FormA]![SubformB].[Form].Requery

    End Sub

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    I have tested your code. The only error is that variable "strSql" is not defined.

    I did not test the update statement. The syntax looks good.

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    strSql = "UPDATE TableData SET TableData.RecordNo = '" & IPrevRecordNo & "' WHERE (((TableData.[No])='" & iStartNo & "'));"
    The single quote delimeter should be used only when the data type is "Text". You have declared the RecordNo as long, performed calculations too.
    Till you get the correct result, remove the WArnings off code. Further, you can use instead of DoCmd.RunSQL
    Code:
    CurrentDb.Execute strSQL,dbfailonError

  4. #4
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    amrut is right about the text vs number compare. Good catch.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, be aware that "No" is a reserved word in Access and shouldn't be used for object names....

    http://allenbrowne.com/AppIssueBadWord.html

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

Similar Threads

  1. Update Table from Form
    By NISMOJim in forum Forms
    Replies: 12
    Last Post: 10-28-2013, 01:30 PM
  2. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  3. Use a form to Update a table
    By j2curtis64 in forum Forms
    Replies: 0
    Last Post: 04-05-2011, 10:18 AM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM

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