I've done some more research and testing on my own (since I haven't gotten any new replies lately!) I thought I had it figured out with the addition of
ActiveWorkbook.Save
ActiveWorkbook.Close
at the end of my Submit button code, BUT although the form now still auto-saves and then does autoclose, when I re-open it the contents of the userform fields have not cleared! I thought that if I placed the additional code AFTER the ClearContents code, everything would work! Does anyone have any ideas??? The code for my Submit button is below, with the additional Save and Close code added:
Sub UpdateLogWorksheet()
Dim Msg As String, Ans As Variant
Msg = "Did you print a copy of your Request Form for your records?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myCopy As Range
Dim myTest As Range
Dim lRsp As Long
Dim OutApp As Object
Dim OutMail As Object
Dim StrBody As String
Dim FileName As String
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("RequestData")
oCol = 2 'order info is pasted on data sheet, starting in this column
'cells to copy from Input sheet - some contain formulas
Set myCopy = inputWks.Range("OrderEntry")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With historyWks
nextRow = .Cells(.Rows.Count, "B").End(xlUp).Offset(1, 0).Row
End With
With inputWks
'mandatory fields are tested in hidden column
Set myTest = myCopy.Offset(0, 2)
If Application.Count(myTest) > 0 Then
MsgBox "Please fill in all the cells!"
Exit Sub
End If
End With
With historyWks
'copy the order data and paste onto data sheet
myCopy.Copy
.Cells(nextRow, 2).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False
End With
'Call the function with the correct arguments
'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet not have to be active then)
FileName = RDB_Create_PDF(Source:=ActiveSheet, _
FixedFilePathName:="", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName < > "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:="email@company.com", _
StrCC:="email@company.com", _
StrBCC:="", _
StrSubject:="New Photography Request Form", _
Signature:=True, _
Send:=False, _
StrBody:="A new Photography Request Form has been entered; please see attached PDF file."
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
Set OutMail = Nothing
Set OutApp = Nothing
Case vbNo
GoTo Quit:
End Select
Quit:
'clear input cells that contain constants
With inputWks
On Error Resume Next
With myCopy.Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
Bookmarks