Private Sub SaveAndNewBtn_Click()
On Error GoTo SaveAndNewBtn_Click_Err
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim rs As DAO.Recordset
Dim lngPO As Long
Dim oRange As Range
If Nz(Me.OrderValue, "") = "" Then
MsgBox "You must enter the value of the order", vbOKOnly
Exit Sub
End If
Me.Dirty = False
lngPO = Me!PO
Set rs = Me.RecordsetClone
rs.FindFirst "po = " & lngPO
Me.OrderValue.SetFocus
Call ImportDocument
Set oBook = objExcelApp.Workbooks.Open(Me.SelectedFile.Text, , False, , , , True, , , True)
Set oSheet = oBook.Sheets(1)
If Me.SelectedFile.Text = "order form*" Then
oSheet.Rows("2:2").Select
objExcelApp.Selection.Insert Shift:=xlDown
Set oRange = oSheet.Range("A2")
With oRange
.Offset(0, 0).Value = rs!PONumber
.Offset(0, 2).Value = rs!PODate
.Offset(0, 3).Value = DLookup("OrderedByName", "tblOrderedBy", "OrderedByID = " & Nz(rs!OrderedBy, 0)) & ""
.Offset(0, 5).Value = rs!Description
.Offset(0, 7).Value = rs!Quantity
.Offset(0, 10).Value = rs!OrderValue
.Offset(0, 18).Value = rs!ETA
.Offset(0, 19).Value = DLookup("SiteName", "tblSite", "SiteID = " & Nz(rs!SiteID, 0)) & ""
End With
Else
'If Me.SelectedFile.Text = "Orders Placed*" Then
oSheet.Rows("2:2").Select
objExcelApp.Selection.Insert Shift:=xlDown
Set oRange = oSheet.Range("A2")
With oRange
.Offset(0, 0).Value = rs!PONumber
.Offset(0, 2).Value = rs!PODate
.Offset(0, 6).Value = DLookup("OrderedForName", "tblOrderedFor", "OrderedForID = " & Nz(rs!OrderedFor, 0)) & ""
.Offset(0, 5).Value = rs!Description
.Offset(0, 7).Value = rs!OrderValue
.Offset(0, 3).Value = DLookup("SupplierName", "Supplier", "SupplierID = " & Nz(rs!SupplierID, 0)) & ""
.Offset(0, 4).Value = DLookup("SiteName", "tblSite", "SiteID = " & Nz(rs!SiteID, 0)) & ""
End With
'...
oBook.Save
'Set oSheet = Nothing
oBook.Close savechanges:=True
Set oBook = Nothing
On Error Resume Next
DoCmd.GoToRecord , "", acNewRec
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
SaveAndNewBtn_Click_Exit:
Exit Sub
SaveAndNewBtn_Click_Err:
MsgBox Error$
Resume SaveAndNewBtn_Click_Exit
End If
'End If
End Sub