Re: The Bestest Practice
Beautiful. Almost 9 years later and I am still sending co-workers a link to this thread.
Re: The Bestest Practice
Beautiful. Almost 9 years later and I am still sending co-workers a link to this thread.
Re: Google Chrome. New Web Browser
Viva La SeaMonkey! =)
Re: Export Data From Access Via Userform
1. "strSQL" has to be the name of a saved query in Access.
2. Remove the last comma.
3. "A1" should be a fully qualified range that includes the sheet name: "SheetName!A1"
Re: Code To Generate Data Table
I think that "Selection" is activesheet dependent. So essentially, you are specifying a cell on a different sheet for your columninput argument. Perhaps you should define a variable of type range named TableRange and set it equal to the selection on sheet Calculator. Then you should be able to use TableRange.Table ColumnInput = RefCell. I've never dealt with a Range.Table object via VBA before so this is all a best guess on my part.
hth,
Mavyak
Re: Export Data From Access Via Userform
Try DoCmd.TransferSpreadsheet
Re: Remove Or Delete Duplicate Rows
That is slick, Reafidy. Very nice!
Re: Remove Or Delete Duplicate Rows
I'm interested in seeing how that will work. I understand that you will have the sum of all the records after the duplicates are removed but I believe Rajala needs the values summed at the duplicate level (essentially a group by for the first five columns and a sum on the sixth). The first thing that comes to my mind is SQL via ADO:
Sub Remove_Dups_And_Sum_Column_F()
Dim c As New ADODB.Connection
Dim r As New ADODB.Recordset
Dim w As Worksheet
Dim x As Integer
ThisWorkbook.Names.Add "MyTable", "=Original!" & ThisWorkbook.Worksheets("Original").Range("A1:F" & ThisWorkbook.Worksheets("Original").Range("A1").End(xlDown).Row).Address
c.Open "Provider=Microsoft.Jet.OleDb.4.0;data source=" & ThisWorkbook.FullName & ";Extended Properties=Excel 8.0;"
r.Open "SELECT PART, D1, D2, S, Material, SUM(Amount) AS Amount FROM MyTable GROUP BY PART, D1, D2, S, Material", c, adOpenForwardOnly, adLockOptimistic
ThisWorkbook.Names("MyTable").Delete
Set w = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
w.Name = "Original_New"
w.Range("A2").CopyFromRecordset r
For x = 0 To r.Fields.Count - 1
w.Range("A1").Offset(0, x) = r.Fields(x).Name
Next x
ExitSub:
Set w = Nothing
Set p = Nothing
If Not r Is Nothing Then
If r.State <> adStateClosed Then
r.Close
End If
Set r = Nothing
End If
If Not c Is Nothing Then
If c.State <> adStateClosed Then
c.Close
End If
Set c = Nothing
End If
Exit Sub
End Sub
Display More
That code puts the result set in a new worksheet leaving the original values intact. It could be quickly edited to replace the original values with the result set, though.
Re: Outlook, Recognise Email, Save Attachment, Move Email To A Subfolder
What is the error that you get?
Re: Outlook, Recognise Email, Save Attachment, Move Email To A Subfolder
Option Explicit
Sub GetAttachments_From_Inbox()
On Error GoTo GetAttachments_err
' Declare variables
Dim appOl As New Outlook.Application
Dim ns As Outlook.Namespace
Dim Inbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim Item As Object
'Dim Item As Outlook.Items
Dim Atmt As Outlook.Attachment
Dim FileName As String
Dim i As Integer
Dim sender As String
Dim ext As String
Dim Items As Outlook.Items
Dim oc As Object
Dim moveEmail As Boolean
Set ns = appOl.GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set Item = Inbox.Items
Set myDestFolder = Inbox.Folders("Personal Mail")
'Set oc = Application.ActiveInspector.CurrentItem
i = 0
' Check Inbox for messages and exit if none found
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If
' Check each message for attachments
For Each Item In Inbox.Items
'Resets teh moveEmail check-flag to false for
'processing the next Email in the collection
moveEmail = False
'Identify the sender here
sender = Right(Item.SenderEmailAddress, Len(Item.SenderEmailAddress) - InStrRev(Item.SenderEmailAddress, "="))
'We only care about attachments or moving the email if the email is
'from a specific sender, so skip processing if get_bank(sender) = unknown
If get_bank(sender) <> "unknown" Then
' Save any attachments found
For Each Atmt In Item.Attachments
'We only care about Excel workbooks so skip other attachments
If UCase(Right(Atmt.FileName, 4)) = ".XLS" Then
'Email has passed all checks:
' 1. From specific sender
' 2. Has attachments
' 3. At least one attachment is an Excel workbook
'so we set the moveEmail check-flag to True
moveEmail = True
ext = Atmt.FileName
ext = Right(ext, Len(ext) - InStrRev(ext, ".") + 1)
FileName = "S:\Loans\Data\For\Outlook\" & get_bank(sender) & ext
'Atmt.SaveAsFile FileName
Atmt.SaveAsFile FileName
i = i + 1
End If
Next Atmt
'this line is inside the if block but outside the attachment loop
'so the email will only get moved once per applicable email that
'had an Excel workbook as an attachment.
If moveEmail Then
Item.Move myDestFolder
End If
End If
Next Item
' Show summary message
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
End If
' Clear memory
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Set appOl = Nothing
Exit Sub
' Handle errors
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub
Function get_bank(sender As String) As String
Select Case sender
Case "[email protected]"
get_bank = "nameb"
Case Else
get_bank = "unknown"
End Select
End Function
Display More
Re: Outlook, Recognise Email, Save Attachment, Move Email To A Subfolder
For Each Item In Inbox.Items
If get_bank(Sender) <> "unknown" Then
' Save any attachments found
For Each Atmt In Item.Attachments
' This filename path must exist! Change folder name as necessary.
Sender = Atmt.Parent.SenderEmailAddress
Sender = Right(Sender, Len(Sender) - InStrRev(Sender, "="))
ext = Atmt.Filename
ext = Right(ext, Len(ext) - InStrRev(ext, ".") + 1)
Filename = "S:\Loans\Data\For\Outlook\" & get_bank(Sender) & ext
'Atmt.SaveAsFile FileName
Atmt.SaveAsFile Filename
i = i + 1
Next Atmt
Item.Move myDestFolder
End If
Next Item
Display More
I think that will work. Not positive, though. It's untested.
Re: Uploading Multiple Records From .xls To Sql Server As Single Batch (ado/jet/odbc)
Can you create the staging table and a stored procedure to move the data from the staging table to the live table? That way, Excel would run the data to the staging table and upon completion of the upload the same ADO connection could be used to call the stored procedure to move the data from the staging table to the live table. That way, your trigger would remain intact and would only fire once for the stored procedure.
Re: Running Sum Until
I'm pretty sure this can be done in Oracle and possibly SQL Server too. I don't believe Access has the ability. If the tables in Access are actually linked tables to an Oracle or SQL Server back-end then we could use native SQL via a pass-through query to return the results you're looking for. In Oracle, the following would produce a running total of a field named TRADE_AMOUNT (titled RUNNING_TOTAL) in the reverse order of the time the trades occurred:
SELECT
[indent]TRADE_ID,
TRADE_DATE,
SECURITY_ID,
TRADE_AMOUNT,
TRADE_AMOUNT + LAG(TRADE_AMOUNT, 1, 0) OVER (ORDER BY TRADE_DATE DESC) AS RUNNING_TOTAL[/indent]
FROM
[indent]TRADES[/indent]
Re: E.spreadsheet Designer Sql Reports
sub create_excel_report_from_sql
dim c as adodb.connection
dim r as adodb.recordset
set c = new adodb.connection
c.open "your database connection string here"
set r = new adodb.recordset
set r = c.execute("your sql statement here")
thisworkbook.worksheets(1).range("A1").copyfromrecordset r
r.close
c.close
set r = nothing
set c = nothing
end sub
Display More
No charge...
Re: Convert Numbers Into Hour And Minute In Access
Where do you need the results displayed?
Re: Calculation On Table
SELECT
[INDENT]T1.Product_Code, (T1.value/T2.Value) As Product_Value[/INDENT]
INTO
[INDENT]NEWTABLE1[/INDENT]
FROM
[INDENT]TABLE1 T1[/INDENT]
[INDENT]INNER JOIN TABLE2 T2 ON T1.Product_Code = T2.Product_Code[/INDENT]
Re: Concurrent 80004005 And 80040e14 With Ado Jet
You can also add:
as well as:
ExitSub:
If Not cn Is Nothing Then
If cn.State <> adStateClosed Then
cn.Close
End If
Set cn = Nothing
End If
If Not rs Is Nothing Then
If rs.State <> adStateClosed Then
rs.Close
End If
Set rs = Nothing
End If
Exit Sub
errHandler:
If cn.Errors.Count > 0 Then
Debug.Print "ADO Error #" & cn.Errors(0).NativeError & ": " & cn.Errors(0).Description
cn.Errors.Clear
Else
Debug.Print "VBA Error #" & Err.Number & ": " & Err.Description
Err.Clear
End If
Stop
Resume ExitSub
Display More
to the end. The Connection object might have a better description of the error in question.
Re: Add Attachment To Email
I'm kind of out of my element with the Outlook object model but I do have two possibilities:
1. An alternate spelling for Cancellation is to use one "l" (e.g. Cancelation). Is the file spelled the same way in your code as it is on your harddrive?
2. I don't believe you need to enclose the file name in parentheses, only quotation marks. Parentheses usually indicate that the associated function is returning a value to a variable. In this case it is not.
hth,
Mav