My Project is developed in MS-Access 2010 and Back end is SQL Server 2016.I connect the back end with ODBC. I install the system in my PCs and it working good but in one PC, whenever the user try to submit he get the same error
! [Error image] https://ibb.co/fCV6JGF
I delete the old ODBC connection and create a "New" connection through SQL Server.Before I replace the Source code folder with new one.But the same Error occur.
Private Sub cmdPostSubmit_Click()
postSubmit = 1
postOnly = 0
If TestOutlookIsOpen = True Then
Else
If UCase (Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
MsgBox "Outlook is not open", vbCritical + vbOKOnly
Exit Sub
End If
End If
If (Nz(Trim(DLookup("fldAllStatus", "TBL_REQUEST_STATUS","fldTrackNo=
'" & gTrackNo & "'"))) = "Unprocessed")
Then Msgbox "attach the docs",vbCritical + vbOKOnly
Exit Sub
If Me.cmdPostSubmit.Caption = "Submit" Then
If (Trim(DLookup("fldUnitName", "TBL_USER", "fldNetID = '" & Trim(gNetID) & "'")) = Trim(hostUNIT)) Then
'If (Nz(DLookup("count(fldTrackNo)", "TBL_FILE_ATTACHMENT", "fldTRackNo = '" & gTrackNo & "'")) = 0 And Me.chkRet.Value = 0) Then
' MsgBox "This request must be returned and cannot be processed due to lack of attachments.", vbInformation + vbOKOnly
' Exit Sub
'End If
If (Me.chkRet.Value = -1) Then
If MsgBox("Are your sre you want to return this request unrpocessed ?", vbQuestion + vbYesNo) = vbYes Then
If Nz(Me.txtRemarks.Value) = "" Then
MsgBox "Please write something in the remarks to proceed ... ", vbInformation + vbOKOnly
Exit Sub
Else
'Save the current request status prior to updating
saveUnprocessedStatus gTrackNo, Trim(DLookup("fldAllStatus", "TBL_REQUEST_STATUS", "fldTrackNo = '" & gTrackNo & "'"))
CurrentDb.Execute "UPDATE TBL_REQUEST_STATUS SET fldAllStatus = 'Unprocessed',fldReqStatus = 'Unprocessed' WHERE fldTrackNo = '" & gTrackNo & "'"
CurrentDb.Execute "UPDATE TBL_REQUEST_APPROVAL SET fldReqStatus = 'Unprocessed' WHERE fldTrackNo = '" & gTrackNo & "'"
End If
Else
Exit Sub
End If
End If
If Nz(Me.txtRemarks.Value) = "" Then
MsgBox "Please write something in the remarks ... ", vbInformation + vbOKOnly
Exit Sub
End If
End If
updateValuesDetails 'Download and update the details
MsgBox "Request Successfully Posted And Submitted !!!", vbInformation + vbOKOnly
If UCase(Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
clsMail.sendMailForStepUpRequest
End If
Else
uploadValuesDetails 'Download and save the details
MsgBox "Request Successfully Posted And Submitted !!!", vbInformation + vbOKOnly
If UCase(Trim(Me.cboAllStatus.Value)) = "STEPPED UP" Then
clsMail.sendMailForStepUpRequest
End If
disableMainButt 0
Forms![FRM_MAIN].Form.cmdNewRequest.SetFocus
Forms![FRM_MAIN]![subForm].SourceObject = "FRM_REQ_STATUS"
'' RELOAD MASTER LIST
strSQL = "SELECT TBL_REQUEST_STATUS.fldTrackNo,TBL_REQUEST_STATUS.fldJobTitle, TBL_REQUEST_STATUS.fldReqStatus, TBL_REQUEST_STATUS.fldDateInitiated,"
strSQL = strSQL & "TBL_REQUEST_STATUS.fldReqBy, TBL_REQUEST_STATUS.fldUnitApp, TBL_REQUEST_STATUS.fldEDURec, TBL_REQUEST_STATUS.fldEDUApp,"
strSQL = strSQL & "TBL_REQUEST_STATUS.fldPercentage, TBL_WORKFLOW_APPROVAL.fldUnitApproved, TBL_WORKFLOW_APPROVAL.fldEDUEvaluated, TBL_WORKFLOW_APPROVAL.fldEDUApproved,"
strSQL = strSQL & "TBL_WORKFLOW_APPROVAL.fldDivApproved,TBL_REQUEST_APPROVAL.fldNetID,TBL_WORKFLOW_APPROVAL.fldAssignedEngr,TBL_REQUEST_STATUS.fldAllStatus,TBL_REQUEST_STATUS.fldAllperc,TBL_REQUEST_STATUS.fldAllRemarks FROM
TBL_REQUEST_APPROVAL RIGHT JOIN (TBL_WORKFLOW_APPROVAL RIGHT JOIN TBL_REQUEST_STATUS ON TBL_WORKFLOW_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo) ON TBL_REQUEST_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo "
'strSQL = strSQL & "TBL_WORKFLOW_APPROVAL.fldDivApproved FROM TBL_WORKFLOW_APPROVAL RIGHT JOIN TBL_REQUEST_STATUS ON TBL_WORKFLOW_APPROVAL.fldTrackNo = TBL_REQUEST_STATUS.fldTrackNo "
If IsCADOPR2(gNetID) Then
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE (TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed')
AND (fldCADopr = '" & gNetID & "' OR fldCAD1 = '" & gNetID & "' OR fldCAD2 = '" & gNetID & "' OR fldCAD3 = '" & gNetID & "' OR fldCAD4 = '" & gNetID & "') ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC" 'OR fldReqBy = '" & gNetID & "') AND fldUnitName = '" & gUnitDesc & "'"
ElseIf IsEDUMember(gNetID) Then
If Trim(DLookup("fldPosLevel", "TBL_USER", "fldNetID = '" & Trim (gNetID) & "'")) = "DRAFTSMAN" Then
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE TBL_WORKFLOW_APPROVAL.fldAssignedEngr = '" & gNetID & "' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
Else
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
End If
Else
Forms![FRM_MAIN]![subForm]![subForm3].Form.RecordSource = strSQL & " WHERE fldUnitName = '" & gUnitDesc & "' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Completed' AND TBL_REQUEST_STATUS.fldAllStatus <> 'Cancelled' AND
TBL_REQUEST_STATUS.fldAllStatus <> 'Unprocessed' ORDER BY TBL_REQUEST_STATUS.fldDateInitiated DESC"
End If
End If
setUpAccessLevel
End Sub
On Clicking the Submit it will be saved in the SQL database but it throw the error message.
As a general rule, anytime you going to run reports, query additional data, you would do BEYOND well to FIRST save the current record in the current context. In addition, if this is a new record, then un-like Access tables, the default values, and PK generation does NOT occur until such time you saved the current record.
so, in you code, you want to safe tuck away the current record. This will allow SQL server to setup the PK values and any default columns. So
Private Sub cmdPostSubmit_Click()
postSubmit = 1
postOnly = 0
If me.Dirty = True then me.Dirty = False ' save current record to table.
The other issue is does your code work for existing records, and not new ones, or does it always error out?
来源:https://stackoverflow.com/questions/57569272/the-user-not-able-to-submit-the-form-and-get-the-error-invalid-use-of-null