R
requeth
Hello, I am having issues with the following code. Issues are:
1. My insert statement does not insert the data into my table, though
it did before I started programming in the form logic after it.
2. In my messagebox asking "Will it be for the same user?" no matter
if I hit yes or no the vbYes statement runs.
Any ideas what I am doing wrong here? I did add the tableopen, table
save, and table close after the insert statement stopped working, so
if that is incorrect it was after the fact.
Thanks!
Option Compare Database
Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function PaperAuditInsert() As String
Dim sqlInsertStatement As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim spctnamesave As String
Dim spctfxsave As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
v_user = GetUserName
DoCmd.OpenTable "PAPERAUDIT_TABLE", acViewNormal, acEdit
sqlInsertStatement = "Insert into PAPERAUDIT_TABLE([PA_SPCT_FX],
[PA_QA_FX],[PA_DCN],[PA_SPCT_NAME]," _
& "[PA_AUDIT_DATE]," _
& "[PA_AUDIT_TIME],[PA_TID],[PA_APPLICANT_NAME],[PA_SUBMIT_REASON],
[PA_REQ1],[PA_REQ2],[PA_REQ3]," _
& "[PA_REQ4],[PA_REQ5]," _
& "[PA_REQ6],[PA_REQ7],[PA_REQ_PE1],[PA_REQ_PE2],[PA_REQ_PE3],
[PA_REQ_PE4],[PA_REQ_PE5],[PA_REQ_PE6]," _
& "[PA_REQ_PE7]," _
& "[PA_REQ_COMM1],[PA_REQ_COMM2],[PA_REQ_COMM3],[PA_REQ_COMM4],
[PA_REQ_COMM5],[PA_REQ_COMM6]," _
& "[PA_REQ_COMM7])" _
& "Values('" & [Forms]![PAPER_AUDIT]![spctid] & "','" & v_user & "','"
& [Forms]![PAPER_AUDIT]![dcn] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![spctname] & "','" & [Forms]!
[PAPER_AUDIT]![auditdate] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![timeaudit] & "','" & [Forms]!
[PAPER_AUDIT]![trackingid] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![appname] & "','" & [Forms]!
[PAPER_AUDIT]![submitbox] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail1] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail2] & "'" _
& ",'" & [Forms]![PAPER_AUDIT]![p_avail3] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail4] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail5] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail6] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail7] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e1] & "','" & [Forms]![PAPER_AUDIT]!
[p_e2] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e3] & "','" & [Forms]![PAPER_AUDIT]!
[p_e4] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e5] & "','" & [Forms]![PAPER_AUDIT]!
[p_e6] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e7] & "','" & [Forms]![PAPER_AUDIT]!
[comm1] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm2] & "','" & [Forms]![PAPER_AUDIT]!
[comm3] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm4] & "','" & [Forms]![PAPER_AUDIT]!
[comm5] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm6] & "','" & [Forms]![PAPER_AUDIT]!
[comm7] & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
MsgBox "Statement should have run."
DoCmd.SetWarnings True
DoCmd.Save acTable, "PAPERAUDIT_TABLE"
DoCmd.Close acTable, "PAPERAUDIT_TABLE", acSaveYes
MsgBox "Would you like to fill this form out again?", vbYesNo
If vbYes Then MsgBox "Will it be for the same user?", vbYesNo
If vbYes Then
spctnamesave = Forms!PAPER_AUDIT!spctname
spctfxsave = Forms!PAPER_AUDIT!spctid
'MsgBox spctfxsave
'MsgBox spctnamesave
DoCmd.Close acForm, "PAPER_AUDIT", acSaveNo
DoCmd.OpenForm "PAPER_AUDIT"
Forms!PAPER_AUDIT!spctname = spctnamesave
Forms!PAPER_AUDIT!spctid = spctfxsave
ElseIf vbNo Then
DoCmd.Close acForm, "PAPER_AUDIT", acSaveNo
DoCmd.OpenForm "PAPER_AUDIT"
Else
DoCmd.Close acForm, PAPER_AUDIT, acSaveNo
DoCmd.OpenForm mainmenu
End If
End Function
1. My insert statement does not insert the data into my table, though
it did before I started programming in the form logic after it.
2. In my messagebox asking "Will it be for the same user?" no matter
if I hit yes or no the vbYes statement runs.
Any ideas what I am doing wrong here? I did add the tableopen, table
save, and table close after the insert statement stopped working, so
if that is incorrect it was after the fact.
Thanks!
Option Compare Database
Public Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function PaperAuditInsert() As String
Dim sqlInsertStatement As String
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim spctnamesave As String
Dim spctfxsave As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
v_user = GetUserName
DoCmd.OpenTable "PAPERAUDIT_TABLE", acViewNormal, acEdit
sqlInsertStatement = "Insert into PAPERAUDIT_TABLE([PA_SPCT_FX],
[PA_QA_FX],[PA_DCN],[PA_SPCT_NAME]," _
& "[PA_AUDIT_DATE]," _
& "[PA_AUDIT_TIME],[PA_TID],[PA_APPLICANT_NAME],[PA_SUBMIT_REASON],
[PA_REQ1],[PA_REQ2],[PA_REQ3]," _
& "[PA_REQ4],[PA_REQ5]," _
& "[PA_REQ6],[PA_REQ7],[PA_REQ_PE1],[PA_REQ_PE2],[PA_REQ_PE3],
[PA_REQ_PE4],[PA_REQ_PE5],[PA_REQ_PE6]," _
& "[PA_REQ_PE7]," _
& "[PA_REQ_COMM1],[PA_REQ_COMM2],[PA_REQ_COMM3],[PA_REQ_COMM4],
[PA_REQ_COMM5],[PA_REQ_COMM6]," _
& "[PA_REQ_COMM7])" _
& "Values('" & [Forms]![PAPER_AUDIT]![spctid] & "','" & v_user & "','"
& [Forms]![PAPER_AUDIT]![dcn] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![spctname] & "','" & [Forms]!
[PAPER_AUDIT]![auditdate] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![timeaudit] & "','" & [Forms]!
[PAPER_AUDIT]![trackingid] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![appname] & "','" & [Forms]!
[PAPER_AUDIT]![submitbox] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail1] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail2] & "'" _
& ",'" & [Forms]![PAPER_AUDIT]![p_avail3] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail4] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail5] & "','" & [Forms]!
[PAPER_AUDIT]![p_avail6] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_avail7] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e1] & "','" & [Forms]![PAPER_AUDIT]!
[p_e2] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e3] & "','" & [Forms]![PAPER_AUDIT]!
[p_e4] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e5] & "','" & [Forms]![PAPER_AUDIT]!
[p_e6] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![p_e7] & "','" & [Forms]![PAPER_AUDIT]!
[comm1] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm2] & "','" & [Forms]![PAPER_AUDIT]!
[comm3] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm4] & "','" & [Forms]![PAPER_AUDIT]!
[comm5] & "'," _
& "'" & [Forms]![PAPER_AUDIT]![comm6] & "','" & [Forms]![PAPER_AUDIT]!
[comm7] & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
MsgBox "Statement should have run."
DoCmd.SetWarnings True
DoCmd.Save acTable, "PAPERAUDIT_TABLE"
DoCmd.Close acTable, "PAPERAUDIT_TABLE", acSaveYes
MsgBox "Would you like to fill this form out again?", vbYesNo
If vbYes Then MsgBox "Will it be for the same user?", vbYesNo
If vbYes Then
spctnamesave = Forms!PAPER_AUDIT!spctname
spctfxsave = Forms!PAPER_AUDIT!spctid
'MsgBox spctfxsave
'MsgBox spctnamesave
DoCmd.Close acForm, "PAPER_AUDIT", acSaveNo
DoCmd.OpenForm "PAPER_AUDIT"
Forms!PAPER_AUDIT!spctname = spctnamesave
Forms!PAPER_AUDIT!spctid = spctfxsave
ElseIf vbNo Then
DoCmd.Close acForm, "PAPER_AUDIT", acSaveNo
DoCmd.OpenForm "PAPER_AUDIT"
Else
DoCmd.Close acForm, PAPER_AUDIT, acSaveNo
DoCmd.OpenForm mainmenu
End If
End Function