I have code for a command button on a form. There's a field on the form which the user selects to choose which records to print. I am trying to have the command button first show a message box if no records are selected -
If Me!txtSelected = 0 Then
MsgBox "Please select an Order to print", vbOKOnly, "Error"
and cancel on 'Ok' if none selected. If there are records selected then skip this bit and go to message box 'Are you sure' ok/cancel. Cancel obviously quits, ok calls another sub then opens the report. I would also like to requery the subform at the end.
I've been trying to get my code right but am new to vba and keep getting errors about no if's or if's in the wrong places etc
Here's the code:-
Also, I'm trying to get the UpdateTable function to update the field in the subform 'Processed' to yes for those selected records in the subform. The records are selected with a 'Delivered' yes/no field. I'm not sure I've got this bit quite right either?
Many thanks for any help!!!
If Me!txtSelected = 0 Then
MsgBox "Please select an Order to print", vbOKOnly, "Error"
and cancel on 'Ok' if none selected. If there are records selected then skip this bit and go to message box 'Are you sure' ok/cancel. Cancel obviously quits, ok calls another sub then opens the report. I would also like to requery the subform at the end.
I've been trying to get my code right but am new to vba and keep getting errors about no if's or if's in the wrong places etc
Here's the code:-
Code:
Private Sub btnOpenDelivRpt_Click()
If Me!txtSelected = 0 Then
MsgBox "Please select an Order to print", vbOKOnly, "Error"
Else
MsgBox "Are you sure?", vbOKCancel
End If
If MsgBox("Are you sure?", vbOKCancel) = vbCancel Then Exit Sub
Else
If MsgBox("Are you sure?", vbOKCancel) = vbOK Then
'Send selected records to delivery report.
Call UpdateTable '/ <<<<<<<< Call sub function
DoCmd.OpenReport "rptOrderDeliveries", acViewPreview
End If
Exit Sub
End Sub
Also, I'm trying to get the UpdateTable function to update the field in the subform 'Processed' to yes for those selected records in the subform. The records are selected with a 'Delivered' yes/no field. I'm not sure I've got this bit quite right either?
Code:
Private Sub UpdateTable()
Dim rsTemp As DAO.Recordset
Dim i As Integer
'Create a copy of this forms Recordset
Set rsTemp = Me.fsubUnprocessedOrders.Form.RecordsetClone
rsTemp.MoveFirst
'Loop through all records and update to new value
For i = 1 To rsTemp.RecordCount
If Me.CurrentRecord = True Then
CurrentDb.Execute "UPDATE tblCustomerOrders SET tblCustomerOrders.Processed = Yes where OrderNumber =" & Me.OrderNumber
End If
rsTemp.MoveNext
Next i
'Release resources
rsTemp.Close
Set rsTemp = Nothing
End Sub
Many thanks for any help!!!