Another New record button

T588

Registered User.
Local time
Today, 18:56
Joined
Feb 3, 2003
Messages
65
I have a new record button that runs the code below:

Function NewRecord()
DoCmd.GoToRecord , , acNewRec
End Function

I also have the code below associated with the main form (so it will not update unless all required fields are filled)
Private Sub Form_BeforeUpdate(Cancel As Integer)
' Make sure all required fields are filled in before saving order to table.
' Otherwise, cancel entries made by user.
Dim ctlShipper As ComboBox
Dim cmboSalesPerson As ComboBox
Dim ctlCustomer As ComboBox
Dim ctlShipto As TextBox
Dim ctlReqiredDate As TextBox
On Error GoTo ErrorHandler
Set ctlCustomer = Me!SoldtoName
Set ctlShipper = Me!BranchNumber
Set cmboSalesPerson = Me!Salesperson
Set ctlShipto = Me!ShiptoName
Set ctlRequiredDate = Me!RequiredDate
If IsNull(ctlShipper) Then
MsgBox "Please select FECP Branch.", vbExclamation
Cancel = True
If ctlShipper.Enabled = False Then ctlShipper.Enabled = True
ctlShipper.SetFocus
Exit Sub
End If
If IsNull(cmboSalesPerson) Then
MsgBox "Please select the salesperson for this order.", vbExclamation
Cancel = True
cmboSalesPerson.SetFocus
Exit Sub
End If
If IsNull(ctlCustomer) Then
MsgBox "Please select a Sold To customer.", vbExclamation
ctlCustomer.SetFocus
Cancel = True
Exit Sub
End If
If IsNull(ctlShipto) Then
MsgBox "Please enter Ship to info .", vbExclamation
ctlShipto.SetFocus
Cancel = True
Exit Sub
End If
Exit Sub
ErrorHandler:
MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description
End Sub


When I click the new record button it errors out because of the before update above.

I would like it to give the user the option to cancel or delete the current record (If they decide against completing the order) without jumping into the before update criteria.
Is this possible?

Vince
 
T588 said:
I would like it to give the user the option to cancel or delete the current record (If they decide against completing the order) without jumping into the before update criteria.
Is this possible?

Vince

On a button's click:

Code:
DoCmd.RunCommand acCmdDeleteRecord
 
I'll give this a go.......I'm not sure if this is what I want....
I want a message box to appear with 2 options delete current record or cancel msgbox - if they choose to delete - it creates a new record.

Vince
 
This, then:

Code:
If MsgBox("Do you wish to delete this record?", vbQuestion + vbYesNo, "Confirm Deletion")= vbYes Then
    With DoCmd
        .SetWarnings False
        .RunCommand acCmdDeleteRecord
        .SetWarnings True
        .GotoRecord , , acAddNew
     End With
End If
 
This is a toolbar button that runs a macro - that runs a run command action - that runs VB code.

what I was concerned with is diassociating it with the before update procedure. giving that the form wants to update however it's closed.

running the code you supplied -I don't get the vb windows but it halts the action for each field not filled (Action failed window/ halt)

Do you know how to get around this?

BTW - these toolbar buttons are more trouble than their worth!

Thanks

Vince
 

Users who are viewing this thread

Back
Top Bottom