Hi all,
I am trying to create a button on a form in my db. I have a form called Jobs and a form called customer orders.
I want each job to have one invoice (invoices are created using the customer orders form).
The button is on the jobs form. When clicked I want it to create a new record on the customer orders form and enter the job id and customer id from the jobs form into the customer orders form. Once a record is created I need the same button to just open the relevant record based on the job id and customer id. Each job can only have one invoice, and I have set the one to one relationship in the underlying tables.
My visual basic knowledge is very limited, I have so far managed to make the button open and filter the form by customer id and job id (by stealing code from the access wizzard):
Private Sub invoice_Click()
On Error GoTo Err_invoice_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "CustomerOrders"
stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
stLinkCriteria = "[JobID]=" & Me![JobID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_invoice_Click:
Exit Sub
Err_invoice_Click:
MsgBox Err.Description
Resume Exit_invoice_Click
End Sub
So this code is ok if the record is already created, but on a new job, I want to create a new record with the customer orders form already containing the customer id and job id from the jobs form.
Thanks in advance for any help you can offer,
Adam
I am trying to create a button on a form in my db. I have a form called Jobs and a form called customer orders.
I want each job to have one invoice (invoices are created using the customer orders form).
The button is on the jobs form. When clicked I want it to create a new record on the customer orders form and enter the job id and customer id from the jobs form into the customer orders form. Once a record is created I need the same button to just open the relevant record based on the job id and customer id. Each job can only have one invoice, and I have set the one to one relationship in the underlying tables.
My visual basic knowledge is very limited, I have so far managed to make the button open and filter the form by customer id and job id (by stealing code from the access wizzard):
Private Sub invoice_Click()
On Error GoTo Err_invoice_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "CustomerOrders"
stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
stLinkCriteria = "[JobID]=" & Me![JobID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_invoice_Click:
Exit Sub
Err_invoice_Click:
MsgBox Err.Description
Resume Exit_invoice_Click
End Sub
So this code is ok if the record is already created, but on a new job, I want to create a new record with the customer orders form already containing the customer id and job id from the jobs form.
Thanks in advance for any help you can offer,
Adam