Stephen Byrom
asked on
Adding records
Hi there,
I have a button on an unbound form with the following code attached
Private Sub btnEmailCC_Click()
On Error GoTo Err_btnEmailCC_Click
Dim strWhereCriteria As String
strWhereCriteria = "shipnote = Forms!frmXLNote!txtNoteNum "
Dim Aresponse As Integer
Aresponse = MsgBox("Was the pallet count correct?", vbQuestion + vbYesNo, "Pallets Correct ?")
If Aresponse = vbYes Then
DoCmd.SendObject acSendReport, "rptSpecNote2", acFormatPDF, _
"someone@somewhere.com;som eoneelse@s omewhereel se.com", , , "Despatch Note", _
"Please see attached PDF re latest Despatch Note."
btnUpDate.Visible = True
btnUpDate.SetFocus
btnEmailCC.Visible = False
MsgBox "You must now Update the Call-Off!", vbCritical, "Update!"
End If
If Aresponse = vbNo Then
DoCmd.OpenForm "frmEditCCnote", , , strWhereCriteria
End If
Exit_btnEmailCC_Click:
Exit Sub
Err_btnEmailCC_Click:
MsgBox Err.Description, vbOKOnly, "An Error has occured, please inform S.Byrom"
Resume Exit_btnEmailCC_Click
End Sub
When the user clicks "No" to edit the items shipped it opens a split form which is bound to a table (tblStordProds) and has a button on it to add a record if needed. The code attached to the button is;
Private Sub btnAdd_Click()
On Error GoTo Err_btnClose_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPasteAppend
DoCmd.RunCommand acCmdSaveRecord
MsgBox "You must now change the added Product" & vbCrLf & _
"to the product you missed originally." & vbCrLf & _
"Use the drop-down arrow to change it." & vbCrLf & vbCrLf & _
"DO NOT FORGET TO ADJUST THE QUANTITY!", vbCritical, "IMPORTANT"
Exit_btnClose_Click:
Exit Sub
Err_btnClose_Click:
MsgBox Err.Description, vbOKOnly, "An Error has occured, Please inform S.Byrom"
Resume Exit_btnClose_Click
End Sub
However, when I add a record using the button on the second form and then close it. It does not save the record just added.
Is it because the records are filtered in the open argument from the previous form?
If so, how can I get around this? If not, why will it not add a record to the table?
Thanks as always for your time.
I have a button on an unbound form with the following code attached
Private Sub btnEmailCC_Click()
On Error GoTo Err_btnEmailCC_Click
Dim strWhereCriteria As String
strWhereCriteria = "shipnote = Forms!frmXLNote!txtNoteNum
Dim Aresponse As Integer
Aresponse = MsgBox("Was the pallet count correct?", vbQuestion + vbYesNo, "Pallets Correct ?")
If Aresponse = vbYes Then
DoCmd.SendObject acSendReport, "rptSpecNote2", acFormatPDF, _
"someone@somewhere.com;som
"Please see attached PDF re latest Despatch Note."
btnUpDate.Visible = True
btnUpDate.SetFocus
btnEmailCC.Visible = False
MsgBox "You must now Update the Call-Off!", vbCritical, "Update!"
End If
If Aresponse = vbNo Then
DoCmd.OpenForm "frmEditCCnote", , , strWhereCriteria
End If
Exit_btnEmailCC_Click:
Exit Sub
Err_btnEmailCC_Click:
MsgBox Err.Description, vbOKOnly, "An Error has occured, please inform S.Byrom"
Resume Exit_btnEmailCC_Click
End Sub
When the user clicks "No" to edit the items shipped it opens a split form which is bound to a table (tblStordProds) and has a button on it to add a record if needed. The code attached to the button is;
Private Sub btnAdd_Click()
On Error GoTo Err_btnClose_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPasteAppend
DoCmd.RunCommand acCmdSaveRecord
MsgBox "You must now change the added Product" & vbCrLf & _
"to the product you missed originally." & vbCrLf & _
"Use the drop-down arrow to change it." & vbCrLf & vbCrLf & _
"DO NOT FORGET TO ADJUST THE QUANTITY!", vbCritical, "IMPORTANT"
Exit_btnClose_Click:
Exit Sub
Err_btnClose_Click:
MsgBox Err.Description, vbOKOnly, "An Error has occured, Please inform S.Byrom"
Resume Exit_btnClose_Click
End Sub
However, when I add a record using the button on the second form and then close it. It does not save the record just added.
Is it because the records are filtered in the open argument from the previous form?
If so, how can I get around this? If not, why will it not add a record to the table?
Thanks as always for your time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks dq, I found out what was the problem. The ShipNote number was not copying, so when I re-opened the form using the where condition then naturally the newly added record would not show.
I managed to sort it out.
Thanks for pointing me in the right direction with the where criteria.
I managed to sort it out.
Thanks for pointing me in the right direction with the where criteria.
ASKER
I did as you suggested and also removed the redundant line.
It still doesn't save the record though.