Yes, this is the most current code. I too tried some dummy info for ID 1004, and it worked after about 30 seconds. Because I changed the email addresses for security reasons, when send is clicked it takes a little longer than usual for the info to be entered into the sheets.
Here is the code for entering in the info on the LineItems sheet when invoice pending button is selected and Save button is clicked:
Private Sub SaveButton_Click()
On Error Resume Next
Sheets("INVOICES").Activate
Dim rng As Range
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Dim TextBody As String
Dim ApprovedTextBody As String
Dim Finfo As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Finfo = "All Files (*.*),*.*"
Title = "E-Mail Attachment: Select file to attach."
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
'mail server details
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= mail_server
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
'--------------------------------------
'some code for entering the info onto the INVOICES page comes first
'---------------------------------------
'here is the code to enter in info onto the LineItems sheet
Sheets("LineItems").Activate
Dim LnItmRow As Long
LnItmRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 'here it finds the next empty row, and enters the info into it
'for multiple line items enter new row.
If LnItmBox = True Then
Cells(LnItmRow, 1) = IDNumberBox.Text
Cells(LnItmRow, 2) = PathBox.Text
Cells(LnItmRow, 3) = VendorBox.Text
Cells(LnItmRow, 4) = ApproxUSDBox.Text * Allocation1.Text
If Date1 <> "" Then
Cells(LnItmRow, 5) = Date1.Text
Else
Cells(LnItmRow, 5) = DateBox.Text
End If
If Approver1 <> "" Then
Cells(LnItmRow, 6) = Approver1.Text
Else
Cells(LnItmRow, 6) = ApproverBox.Text
End If
If Location1 <> "" Then
Cells(LnItmRow, 7) = Location1.Text
Else
Cells(LnItmRow, 7) = LocationBox.Text
End If
If ExpCat1 <> "" Then
Cells(LnItmRow, 8) = ExpCat1.Text
Else
Cells(LnItmRow, 8) = ExpCategoryBox.Text
End If
Cells(LnItmRow, 9) = "Allocate " & 100 * Allocation1 & "% to " & Details1
'this code is repeated for line item 2,3,4 and 5 as necessary if there are multiple line items for the invoice
Else
Cells(LnItmRow, 1) = IDNumberBox.Text
Cells(LnItmRow, 2) = PathBox.Text
Cells(LnItmRow, 3) = VendorBox.Text
Cells(LnItmRow, 4) = ApproxUSDBox.Text
Cells(LnItmRow, 5) = DateBox.Text
Cells(LnItmRow, 6) = ApproverBox.Text
Cells(LnItmRow, 7) = LocationBox.Text
Cells(LnItmRow, 8) = ExpCategoryBox.Text
Cells(LnItmRow, 9) = DetailsBox.Text
Cells(LnItmRow, 11) = "Pending"
End If 'end if for 'if multiple'
End If 'if msg box
End If 'if pending approval
'-----------------------------------
' then some code for resetting userform
'-----------------------------------
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
As you can see, when the invoice is pending, the code finds the next empty row in LineItems and enters the data from the userform into that row. But when the invoice is approved, I need the code to search through the rows of the LineItems sheet and find each row with the matching ID number, and enter in the approval date and "Approved" in the correct cell. Does this make sense? I really appreciate your commitment to helping me try and figure this out, rylo!!
Bookmarks