Hutchy
Registered User.
- Local time
- Today, 02:33
- Joined
- Jun 28, 2013
- Messages
- 42
Hello
I am using Access 2007.
Mainform name: Visitors
Fields:
Visitor ID, Company ID, Last Name, First Name, Gender, Telephone No, Next of Kin,
Package (This is a combo box with 2 columns and 5 rows),
Status (This is a combo box with 1 column and 2 rows),
Reservation Date, Duration of Stay
Subform name: Visitors Payments Subform
Fields:
Payment ID, Cost, Discount, Final Cost
I added a button, Generate Payment - with controlname generatepayment, that when pressed on creating a new record, it will update the fields in the subform.
I want the Payment ID to be checked for the highest number and then incremented it by 1.
For the Cost: I want to check if the value in Status is "Resident" or "Non Resident".
If it is "Resident", then Cost will be the value at Duration of Stay * 15500, else it will be the value at Duration of Stay * 18002.
For the Discount: I want the value of Cost * the value at Package's column 1.
For the Final Cost: I want Cost - Discount.
Here's what I had, but kept getting an error:
I am using Access 2007.
Mainform name: Visitors
Fields:
Visitor ID, Company ID, Last Name, First Name, Gender, Telephone No, Next of Kin,
Package (This is a combo box with 2 columns and 5 rows),
Status (This is a combo box with 1 column and 2 rows),
Reservation Date, Duration of Stay
Subform name: Visitors Payments Subform
Fields:
Payment ID, Cost, Discount, Final Cost
I added a button, Generate Payment - with controlname generatepayment, that when pressed on creating a new record, it will update the fields in the subform.
I want the Payment ID to be checked for the highest number and then incremented it by 1.
For the Cost: I want to check if the value in Status is "Resident" or "Non Resident".
If it is "Resident", then Cost will be the value at Duration of Stay * 15500, else it will be the value at Duration of Stay * 18002.
For the Discount: I want the value of Cost * the value at Package's column 1.
For the Final Cost: I want Cost - Discount.
Here's what I had, but kept getting an error:
Code:
Private Sub generatepayment_Click()
If Me.NewRecord = True Then
Me!Visitors_Payments_Subform.Form.Payment_ID = Nz(DMax("Payment_ID", "Payments"), 1) + 1
If Me.Status = Resident Then
Me!Visitors_Payments_Subform.Form.Cost = 15500 * Me.Duration_of_Stay
Else
Me!Visitors_Payments_Subform.Form.Cost = 18002 * Me.Duration_of_Stay
End If
Me!Visitors_Payments_Subform.Form.Discount = Me!Visitors_Payments_Subform.Form.Cost * Me.Package.Column(1)
Me!Visitors_Payments_Subform.Form.Final_Cost = Me!Visitors_Payments_Subform.Form.Cost - Me!Visitors_Payments_Subform.Form.Discount
End If
End Sub