Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    Here is the VBA:
    Private Sub cmdSaveRecord_Click()
    Dim dbs As Database
    Dim sSQL As String
    Dim strMsg As String

    Set dbs = CurrentDb
    sq = Chr$(39) 'single quote
    sSQL = "UPDATE tblECLUData " _
    & "SET (State = " & sq & txtState & sq & "," _
    & "ClaimStatus = " & sq & cboClaimStatus & sq & "," _
    & "ECLUAnalyst = " & sq & cboLITRep & sq & "," _
    & "ECLUMgmt = " & sq & cboECLUMgmt & sq & "," _
    & "Insured = " & sq & cboRptType & sq & "," _
    & "LitAssoc = " & sq & cboLitAssoc & sq & "," _
    & "AsgmntRec = " & sq & txtAsgmntRec & sq & "," _
    & "ClmFileSnt = " & sq & txtClmFileSnt & sq & "," _
    & "LitAnalystCal = " & sq & txtLitAnalystCal & sq & "," _
    & "AsgmntClo = " & sq & txtAsgmntClosed & sq & "," _
    & "TMDiaryDate = " & sq & txtDiary & sq & ")" _
    & "WHERE ClaimNumber = '" & cboFind.value & "'"

    'add/update data to tblECLUData
    If DCount("*", "tblECLUData", "ClaimNumber = '" & Me.txtClaimNumber.value & "'") = 0 Then 'record does not exist
    'insert record
    dbs.Execute " INSERT INTO tblECLUData (State , ClaimNumber , ClaimStatus, ECLUAnalyst, ECLUMgmt, Insured, ReportType, LitAssoc, AsgmntRec, ClmFileSent, LitAnalystCal, AsgmntClo, TMDiaryDate) " & _
    " VALUES('" & Me.txtState & "','" & Me.txtClaimNumber & "','" & Me.cboClaimStatus & "','" & Me.cboLITRep & "','" & Me.cboECLUMgmt & "','" & _


    Me.txtIns & "','" & Me.cboRptType & "','" & Me.cboLitAssoc & "','" & Me.txtAsgmntRec & "','" & _
    Me.txtClmFileSnt & "','" & Me.txtLitAnalystCal & "','" & Me.txtAsgmntClosed & "','" & Me.txtDiary & "')"
    Else
    'record exists
    Debug.Print sSQL
    dbs.Execute sSQL, dbFailOnError
    End If

    strMsg = "Data successfully entered into database."

    MsgBox strMsg, vbOKOnly, "Entry Successful"
    End Sub

    This is what the debug.print displayed:
    UPDATE tblECLUData SET (State = 'Alabama',ClaimStatus = 'Closed',ECLUAnalyst = 'Dan Einslinger',ECLUMgmt = 'Allen Shockey',Insured = 'Supplemental Report',LitAssoc = 'Alice Urome',AsgmntRec = '6/27/2016',ClmFileSnt = '6/27/2016',LitAnalystCal = '6/27/2016',AsgmntClo = '6/27/2016',TMDiaryDate = '6/27/2016')WHERE ClaimNumber = '01-234N-958'

    The debug.print seems to be displaying all of the information on the form, but it still doesn't update the record. The "Run-time error '3144': Syntax error in UPDATE statement" still comes up.

  2. #17
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Code:
    & "TMDiaryDate = " & sq & txtDiary & sq & ")" _
    & " WHERE ClaimNumber = '" & cboFind.value & "'"
    Add the space.

  3. #18
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    I'm still getting the syntax error.

  4. #19
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    sSQL = "UPDATE tblECLUData " _
    & "SET State = " & sq & txtState & sq & "," _
    & "ClaimStatus = " & sq & cboclaimstatus & sq & "," _
    & "ECLUAnalyst = " & sq & cboLITrep & sq & "," _
    & "ECLUMgmt = " & sq & cboECLUMgmt & sq & "," _
    & "Insured = " & sq & cboRptType & sq & "," _
    & "LitAssoc = " & sq & cboLitAssoc & sq & "," _
    & "AsgmntRec = " & sq & AsgmntRec & sq & "," _
    & "ClmFileSnt = " & sq & txtClmFileSnt & sq & "," _
    & "LitAnalystCal = " & sq & txtLitAnalystCal & sq & "," _
    & "AsgmntClo = " & sq & txtAsgmntClosed & sq & "," _
    & "TMDiaryDate = " & sq & "#" & txtDiary & "#" & sq _
    & " WHERE ClaimNumber = " & sq & cboFind & sq


    Let's try it without the parentheses.

  5. #20
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    are you sure all the single quotes are required - assumes all destination fields are text - including TMDiaryDate?

  6. #21
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    There are multiple date fields. So, if I were to update those fields with "#", then it would look like this.

    sSQL = "UPDATE tblECLUData " _
    & "SET (State = " & sq & txtState & sq & "," _
    & "ClaimStatus = " & sq & cboClaimStatus & sq & "," _
    & "ECLUAnalyst = " & sq & cboLITRep & sq & "," _
    & "ECLUMgmt = " & sq & cboECLUMgmt & sq & "," _
    & "Insured = " & sq & cboRptType & sq & "," _
    & "LitAssoc = " & sq & cboLitAssoc & sq & "," _
    & "AsgmntRec = " & "#" & txtAsgmntRec & "#" & "," _
    & "ClmFileSnt = " & "#" & txtClmFileSnt & "#" & "," _
    & "LitAnalystCal = " & "#" & txtLitAnalystCal & "#" & "," _
    & "AsgmntClo = " & "#" & txtAsgmntClosed & "#" & "," _
    & "TMDiaryDate = " & "#" & txtDiary & "#" & ")" _
    & "WHERE ClaimNumber = '" & cboFind.value & "'"

    This is the debug.print that I get:

    UPDATE tblECLUData SET (State = 'Alabama',ClaimStatus = 'Closed',ECLUAnalyst = 'Dan Einslayer',ECLUMgmt = 'Allen Stenson',Insured = 'Supplemental Report',LitAssoc = 'Alice Novak,AsgmntRec = #6/27/2016#,ClmFileSnt = #6/27/2016#,LitAnalystCal = #6/27/2016#,AsgmntClo = #6/27/2016#,TMDiaryDate = #6/27/2016#)WHERE ClaimNumber = '01-234N-958'

  7. #22
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    other than missing a space before WHERE and a single quote after Novak, that looks like it should work

  8. #23
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    Right? But for some reason, it doesn't like the UPDATE statement and always points to the "dbs.Execute sSQL, dbFailOnError" after execution.

  9. #24
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    To debug this, I would try error by elimination.
    Try it with just updating STATE. Then when that works, add the next field and so on until you encounter the error. Then you have narrowed down the problem. Fix that and continue with adding fields.
    Last edited by davegri; 06-29-2016 at 10:20 AM. Reason: clarity

  10. #25
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    Hey friends, I got in touch with someone who was able to provide a different (and simpler) way of doing what I wanted. This is what I have:

    Private Sub cmdSaveRecord_Click()
    Dim rst As DAO.Recordset
    Dim strMsg As String
    Set rst = CurrentDb.OpenRecordset("tblECLUData")

    If DCount("ID", "tblECLUData", "ClaimNumber = '" & Me.cboFind.value & "'") = 0 Then 'record does not exist
    rst.AddNew
    Else
    rst.Edit
    End If

    rst![State] = Me.txtState
    rst![ClaimNumber] = Me.txtClaimNumber
    rst![ClaimStatus] = Me.cboClaimStatus
    rst![ECLUAnalyst] = Me.cboLITRep
    rst![ECLUMgmt] = Me.cboECLUMgmt
    rst![Insured] = Me.txtIns
    rst![ReportType] = Me.cboRptType
    rst![LitAssoc] = Me.cboLitAssoc
    rst![AsgmntRec] = Me.txtAsgmntRec
    rst![ClmFileSent] = Me.txtClmFileSnt
    rst![LitAnalystCal] = Me.txtLitAnalystCal
    rst![AsgmntClo] = Me.txtAsgmntClosed
    rst![TMDiaryDate] = Me.txtDiary


    rst.Update

    rst.Clone
    Set rst = Nothing
    strMsg = "Data successfully entered into database."

    MsgBox strMsg, vbOKOnly, "Entry Successful"
    End Sub
    --------------------------------------------------------------------------------------
    Like I mentioned, this has been working. However, there are certain instances where it saves a duplicate record. I marked the ClaimNumber field as both "Unique" and "Indexed" and in doing so, was prompted whenever a duplicate record was about to be saved, but is there anything that I could do to prevent this from happening altogether? Any input would be beneficial.

    Thank you.

  11. #26
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    but is there anything that I could do to prevent this from happening altogether?
    that's what your dcount is supposed to do. However so far as I can see, you are always editing the first record so not sure your code is working as you think it is.

    But stick with it. Good luck with your project. Regret I don't have any more time to spend on this

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-27-2015, 01:04 PM
  2. Update If EXISTS, Else INSERT
    By Only4Access in forum Programming
    Replies: 11
    Last Post: 03-27-2014, 01:38 PM
  3. Replies: 4
    Last Post: 12-14-2012, 06:33 PM
  4. Insert if not exists to another table.
    By ramindya in forum Queries
    Replies: 1
    Last Post: 06-12-2012, 07:16 PM
  5. if exists UPDATE else INSERT
    By lloyddobler in forum Programming
    Replies: 18
    Last Post: 01-04-2012, 11:35 PM

Tags for this Thread

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