SQL VIEW OF QUERY FOR REPORT:
SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate, ShipTo.ShipName,
ShipTo.Address1, ShipTo.Address2, ShipTo.City, ShipTo.State, ShipTo.ZipCode,
ShipTo.Country, ShipTo.Phone, Orders.ShipDate, Orders.FreightCharge,
Orders.SalesTaxRate, Products.HandlingPct, [Order Details].OrderDetailID,
[Order Details].ProductID, [Order Details].SerialNum, [Order
Details].Quantity, [Order Details].UnitPrice, [Order Details].Discount,
Customers.CompanyName, Customers.BillingAddress, Customers.City,
Customers.StateOrProvince, Customers.PostalCode, Customers.Country,
Customers.PhoneNumber, Customers.ContactFirstName & " " &
Customers.ContactLastName AS [Contact Name], Dealer.DealerName,
Products.ProductName, Products.ProductCode, [Order Details].LineItem,
Orders.PONumber, BillTo.BillTo, BillTo.Address1, BillTo.Address2,
BillTo.City, BillTo.State, BillTo.Country, BillTo.ZipCode, [Order
Details].Notes, Orders.InvoiceNum
FROM ((Customers INNER JOIN ((Orders INNER JOIN ShipTo ON Orders.ShipToID =
ShipTo.ShipToID) INNER JOIN BillTo ON Orders.BillToID = BillTo.BillToID) ON
Customers.CustomerID = Orders.CustomerID) INNER JOIN (Products INNER JOIN
[Order Details] ON Products.ProductID = [Order Details].ProductID) ON
Orders.OrderID = [Order Details].OrderID) INNER JOIN (Dealer INNER JOIN
OrdersDeliverDealer ON Dealer.DealerID =
OrdersDeliverDealer.DeliverDealerID) ON Orders.OrderID =
OrdersDeliverDealer.OrderID
WHERE (((Orders.OrderID)=[Forms]![Orders by Customer]![Orders by Customer
Subform].[form]![OrderID]))
ORDER BY [Order Details].LineItem, Orders.ShipDate;
CODE BEHIND THE ON DATA EVENT PROPERTY:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub
Private Sub Report_Close()
DoCmd.Close acForm, "Print Invoice"
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strContract As String
Dim strSQL As String
On Error GoTo Report_Open_Err
DoCmd.Maximize
If Not IsLoaded(CONST_FORMORDERSCUST) Then
MsgBox "Open the Invoice report using the Preview Invoice button on
the Orders by Customer form."
Cancel = True
Else
strSQL = "SELECT Contracts.ContractNum,
OrderContractControl.ControlNumber " & _
"FROM Contracts INNER JOIN OrderContractControl ON
Contracts.ContractID = OrderContractControl.ContractID " & _
"WHERE OrderContractControl.OrderID = " & _
Forms(CONST_FORMORDERSCUST).Controls("Orders by Customer
Subform").Form.Controls("OrderID")
Set con = CurrentProject.Connection
Set rst = con.Execute(CommandText:=strSQL, options:=adCmdText)
If rst.EOF = False Then
Do While rst.EOF = False
strContract = rst.Fields("ContractNum") & vbNullString & _
": " & rst.Fields("ControlNumber") & vbNullString & "; "
rst.MoveNext
Loop
Me.lblContract.Caption = strContract
End If
End If
Report_Open_Exit:
Exit Sub
Report_Open_Err:
Call Error_Handler(strMod:=CONST_RPTINV, _
strProc:="Report_Open")
Cancel = True
Resume Report_Open_Exit
End Sub
Thanks, JR