1

I have a CompetencyTable in Access and I'm using a VBA code to update the data in the access table, however, the code is running successfully, however, the data is not getting updated in access table.

I have three fields in access table ActualTarget, ActualCompleted, ActualPending. Now Actual Target is defined by the user already and initially Actual Target = Actual Pending. For example, if the Actual Target is 40 then Actual Pending is 40. Now I want the Actual Completed to be incremented from 1,2,3,4 etc and as the number increases in Actual Completed, the number should decrease in Actual Pending.

The code is running without an error but fields are not getting updated.

Following is the code I have developed

Private Sub CommandButtonSubmit_Click()

Dim CseID, Gid, NmofAgnt, Dt, LOB, Accnmbr, WrkTyp, CsNm, DtmtFnd, Validt, Rsn  As String
Dim Gid1, EmpNm As String
Dim ActCm, ActTgt, ActPend As Integer


Gid1 = Environ("USERNAME")
CseID = TextBoxCSID.Text
Gid = TextBoxGID.Value
NmofAgnt = TextBoxNm.Text
Dt = TextBoxDt.Text
LOB = TextBoxLOB.Text
Accnmbr = TextBoxAccNmbr.Text
WrkTyp = TextBoxWrkTyp.Text
CsNm = TextBoxCsNm.Text
DtmtFnd = ComboBoxDetmtFnd.Value
Validt = ComboBoxValidt.Value
Rsn = TextBoxRsn.Text

If ComboBoxValidt.Value = "Yes" Then
    Call connOpen
    rst.Open "SELECT * FROM LoginAdmin WHERE [GlobalID]= '" & Environ("USERNAME") & "'", conn
        If rst.EOF = False Then
            EmpNm = Trim(rst.Fields("EmpName").Value)
        Else
            Exit Sub
        End If
    rst.Close

        strQuery = "INSERT INTO QAAudits ([GlobalIDQA], [EmpName], [CaseID], [GlobalIDAgent], 
[NameofAgent], [DateProcessed], [LOB], " & _
            "[AccntNmbr], [WorkType], [CustomerName], [DeterimentFindings], [Validated]) " & _
        "Values('" & Gid1 & "', '" & EmpNm & "', '" & CseID & "', '" & Gid & "', '" & NmofAgnt & "', 
'" & Dt & "', '" & LOB & "', '" & Accnmbr & "', " & _
            "'" & WrkTyp & "', '" & CsNm & "', '" & DtmtFnd & "', '" & Validt & "')"
    conn.Execute strQuery


    rst.Open "SELECT * FROM CompetencyTable WHERE [GlobalID]= '" & Gid & "'", conn
        If rst.EOF = False Then
            ActCm = Trim(rst.Fields("ActualCompleted").Value)
            ActTgt = Trim(rst.Fields("ActualTarget").Value)
            ActPend = Trim(rst.Fields("ActualPend").Value)
            ActCm = ActCm + 1
            ActPend = ActTgt - ActCm
        End If
        rst.Close


    rst.Open "UPDATE CompetencyTable SET ActualCompleted= " & ActCm & " AND ActualPend= " & ActPend & 
" WHERE [GlobalID]= '" & Gid & "'", conn



Call connclose

MsgBox "Audited Case Submitted Successfully", vbInformation, "Done"
Unload Me
Qualityform.Show

ElseIf ComboBoxValidt.Value = "No" Then

    Call connOpen
        rst.Open "SELECT * FROM LoginAdmin WHERE [GlobalID]= '" & Environ("USERNAME") & "'", conn
            If rst.EOF = False Then
                EmpNm = Trim(rst.Fields("EmpName").Value)
            Else
                Exit Sub
            End If
        rst.Close

        strQuery = "INSERT INTO QAAuditsIncomplete ([GlobalIDQA], [EmpName], [CaseID], 
[GlobalIDAgent], [NameofAgent], [DateProcessed], [LOB]" & _
        "[AccntNmbr], [WorkType], [CustomerName], [DeterimentFindings], [Validated], [Reason])" & _
        "VALUES ('" & Gid1 & "', '" & EmpNm & "', '" & CseID & "', '" & Gid & "', '" & NmofAgnt & "', 
'" & Dt & "', '" & Accnmbr & "'" & _
        "'" & WrkTyp & "', '" & CsNm & "', '" & DtmtFnd & "', '" & Validt & "', '" & Rsn & "')"
        conn.Execute strQuery
    Call connclose

MsgBox "Incomeplete Audit Case Submitted Successfully in Database", vbInformation, "Done"
Unload Me
Qualityform.Show
Else
    MsgBox "Please select Validated or not", vbCritical
End If





End Sub

So there is a form in vba called Audit form when the data will be added from Audit form with combo box validatenter code here value = Yes then it should update the competency table in Actual Completed and Actual Pending

Please help me to get through this!

Many Thanks In Advance!

4
  • Missing comma in [LOB]". If field is number type, do not use apostrophe delimiters. If field is date/time type use # delimiter. Basically same errors as in stackoverflow.com/questions/61622669/… Commented May 9, 2020 at 17:57
  • Instead of opening a recordset just to get EmpName, can use DLookup() domain aggregate function. Commented May 9, 2020 at 18:03
  • How to debug dynamic SQL in VBA Commented May 9, 2020 at 20:52
  • There is no error in the code, however, the database is not getting updated for the following codes rst.Open "UPDATE CompetencyTable SET ActualCompleted= " & ActCm & " AND ActualPend= " & ActPend & " WHERE [GlobalID]= '" & Gid & "'", conn Commented May 10, 2020 at 14:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.