Change Marco into Code ? Need Syntax, Please

D

Dave Elliott

I need to enter the code below this line into the code below it, where and
how do I do this ?
The idea is to not allow the Invoice to be saved of course without a
Customer, etc...

IsNull([Customer ID]) MsgBox "You Must Choose a Customer"


on Error GoTo Err_Command450_Click

Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[Order ID]= Forms![Categories and Products]![Order
ID]"
stDocName = "InvoiceReport"

' Write Order Amount to 'Orders' Table (Total Due)
Forms![Categories and Products]!Field201 = Forms![Categories and
Products]![Total Due]
' Store as Invoice verses Quote
Forms![Categories and Products]!Type = "Invoice"
' Mark invoice as 'Due'
Forms![Categories and Products]!Status = "Due"
Forms![Categories and Products]!pr1 = Forms![Categories and
Products]!Price
Forms![Categories and Products]!pr2 = Forms![Categories and
Products]![Price 2]
Forms![Categories and Products]!pr3 = Forms![Categories and
Products]![Price 3]
Forms![Categories and Products]!pr4 = Forms![Categories and
Products]![Price 4]
Forms![Categories and Products]!pr5 = Forms![Categories and
Products]![Price 5]
Forms![Categories and Products]!pr6 = Forms![Categories and
Products]![Price 6]
Forms![Categories and Products]!pr7 = Forms![Categories and
Products]![Price 7]
Forms![Categories and Products]!pr8 = Forms![Categories and
Products]![Price 8]
Forms![Categories and Products]!pr9 = Forms![Categories and
Products]![Price 9]
Forms![Categories and Products]!pr10 = Forms![Categories and
Products]![Price 10]
Forms![Categories and Products]!pr11 = Forms![Categories and
Products]![Price 11]
Forms![Categories and Products]!pr12 = Forms![Categories and
Products]![Price 12]
Forms![Categories and Products]!pr13 = Forms![Categories and
Products]![Price 13]
Forms![Categories and Products]!pr14 = Forms![Categories and
Products]![Price 14]
Forms![Categories and Products]!pr15 = Forms![Categories and
Products]![Price 15]


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit_Command450_Click:
Exit Sub
 
D

Dave Elliott

No, I'm sorry, I mean where in the code below which is a onclick event do I
put the new code. (Works fine like it is)
Example, before Write Order Amount to 'Orders' Table (Total Due) or
somewhere else in the code ?

Stanko Milošev said:
On before insert, on before update...

Dave Elliott said:
I need to enter the code below this line into the code below it, where and
how do I do this ?
The idea is to not allow the Invoice to be saved of course without a
Customer, etc...

IsNull([Customer ID]) MsgBox "You Must Choose a Customer"


on Error GoTo Err_Command450_Click

Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[Order ID]= Forms![Categories and Products]![Order
ID]"
stDocName = "InvoiceReport"

' Write Order Amount to 'Orders' Table (Total Due)
Forms![Categories and Products]!Field201 = Forms![Categories and
Products]![Total Due]
' Store as Invoice verses Quote
Forms![Categories and Products]!Type = "Invoice"
' Mark invoice as 'Due'
Forms![Categories and Products]!Status = "Due"
Forms![Categories and Products]!pr1 = Forms![Categories and
Products]!Price
Forms![Categories and Products]!pr2 = Forms![Categories and
Products]![Price 2]
Forms![Categories and Products]!pr3 = Forms![Categories and
Products]![Price 3]
Forms![Categories and Products]!pr4 = Forms![Categories and
Products]![Price 4]
Forms![Categories and Products]!pr5 = Forms![Categories and
Products]![Price 5]
Forms![Categories and Products]!pr6 = Forms![Categories and
Products]![Price 6]
Forms![Categories and Products]!pr7 = Forms![Categories and
Products]![Price 7]
Forms![Categories and Products]!pr8 = Forms![Categories and
Products]![Price 8]
Forms![Categories and Products]!pr9 = Forms![Categories and
Products]![Price 9]
Forms![Categories and Products]!pr10 = Forms![Categories and
Products]![Price 10]
Forms![Categories and Products]!pr11 = Forms![Categories and
Products]![Price 11]
Forms![Categories and Products]!pr12 = Forms![Categories and
Products]![Price 12]
Forms![Categories and Products]!pr13 = Forms![Categories and
Products]![Price 13]
Forms![Categories and Products]!pr14 = Forms![Categories and
Products]![Price 14]
Forms![Categories and Products]!pr15 = Forms![Categories and
Products]![Price 15]


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit_Command450_Click:
Exit Sub
 
K

Ken Snell

I'm guessing that you want the data validation before you open the form?

Change your code to this (I've put comments above and below the new lines):

on Error GoTo Err_Command450_Click

Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[Order ID]= Forms![Categories and Products]![Order
ID]"
stDocName = "InvoiceReport"

' **** START OF NEW LINES ****
If IsNull([Customer ID]) =True Then
MsgBox "You Must Choose a Customer"
Else
' **** END OF NEW LINES ****

' Write Order Amount to 'Orders' Table (Total Due)
Forms![Categories and Products]!Field201 = Forms![Categories and
Products]![Total Due]
' Store as Invoice verses Quote
Forms![Categories and Products]!Type = "Invoice"
' Mark invoice as 'Due'
Forms![Categories and Products]!Status = "Due"
Forms![Categories and Products]!pr1 = Forms![Categories and
Products]!Price
Forms![Categories and Products]!pr2 = Forms![Categories and
Products]![Price 2]
Forms![Categories and Products]!pr3 = Forms![Categories and
Products]![Price 3]
Forms![Categories and Products]!pr4 = Forms![Categories and
Products]![Price 4]
Forms![Categories and Products]!pr5 = Forms![Categories and
Products]![Price 5]
Forms![Categories and Products]!pr6 = Forms![Categories and
Products]![Price 6]
Forms![Categories and Products]!pr7 = Forms![Categories and
Products]![Price 7]
Forms![Categories and Products]!pr8 = Forms![Categories and
Products]![Price 8]
Forms![Categories and Products]!pr9 = Forms![Categories and
Products]![Price 9]
Forms![Categories and Products]!pr10 = Forms![Categories and
Products]![Price 10]
Forms![Categories and Products]!pr11 = Forms![Categories and
Products]![Price 11]
Forms![Categories and Products]!pr12 = Forms![Categories and
Products]![Price 12]
Forms![Categories and Products]!pr13 = Forms![Categories and
Products]![Price 13]
Forms![Categories and Products]!pr14 = Forms![Categories and
Products]![Price 14]
Forms![Categories and Products]!pr15 = Forms![Categories and
Products]![Price 15]


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

' **** START OF NEW LINE ****
End If
' **** END OF NEW LINE ****

Exit_Command450_Click:
Exit Sub

--
Ken Snell
<MS ACCESS MVP>

Dave Elliott said:
I need to enter the code below this line into the code below it, where and
how do I do this ?
The idea is to not allow the Invoice to be saved of course without a
Customer, etc...

IsNull([Customer ID]) MsgBox "You Must Choose a Customer"


on Error GoTo Err_Command450_Click

Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = "[Order ID]= Forms![Categories and Products]![Order
ID]"
stDocName = "InvoiceReport"

' Write Order Amount to 'Orders' Table (Total Due)
Forms![Categories and Products]!Field201 = Forms![Categories and
Products]![Total Due]
' Store as Invoice verses Quote
Forms![Categories and Products]!Type = "Invoice"
' Mark invoice as 'Due'
Forms![Categories and Products]!Status = "Due"
Forms![Categories and Products]!pr1 = Forms![Categories and
Products]!Price
Forms![Categories and Products]!pr2 = Forms![Categories and
Products]![Price 2]
Forms![Categories and Products]!pr3 = Forms![Categories and
Products]![Price 3]
Forms![Categories and Products]!pr4 = Forms![Categories and
Products]![Price 4]
Forms![Categories and Products]!pr5 = Forms![Categories and
Products]![Price 5]
Forms![Categories and Products]!pr6 = Forms![Categories and
Products]![Price 6]
Forms![Categories and Products]!pr7 = Forms![Categories and
Products]![Price 7]
Forms![Categories and Products]!pr8 = Forms![Categories and
Products]![Price 8]
Forms![Categories and Products]!pr9 = Forms![Categories and
Products]![Price 9]
Forms![Categories and Products]!pr10 = Forms![Categories and
Products]![Price 10]
Forms![Categories and Products]!pr11 = Forms![Categories and
Products]![Price 11]
Forms![Categories and Products]!pr12 = Forms![Categories and
Products]![Price 12]
Forms![Categories and Products]!pr13 = Forms![Categories and
Products]![Price 13]
Forms![Categories and Products]!pr14 = Forms![Categories and
Products]![Price 14]
Forms![Categories and Products]!pr15 = Forms![Categories and
Products]![Price 15]


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit_Command450_Click:
Exit Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top