Hello!
I am stumped... I have several make-table queries I run in different Access databases that I run VB code from a button on a form that executes the query, makes the table, and emails it to selected recipients. Is there a way to run and email the query/table from one datadase in another? Here is my attempt so far (failed). I am guessing I need to set the focus somehow to the second db but am not having any luck. Would I need to re-set focus to the main db before I close out of the database? Apologies for not being smarter- I am self taught and cannot get this one.
Private Sub Command1_Click()
Dim strLoc As String, strRun As String
Dim strQry_Name, strTbl_Name As String
Dim strTo As String
Dim strSubject As String
Dim strMessage As String
Dim strDB As String
strQry_Name = "QA Report MR11 2 MT"
strTbl_Name = "MR 2011"
strTo = "Mike"
strSubject = "QA Report: " & Now()
strDB = "Z:\__Mike\VSM_BAC.mdb"
DoCmd.SetWarnings False
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("Z:\__Mike\VSM_BAC.mdb")
accapp.Visible = True
[strDB].SetFocus
DoCmd.OpenQuery "QA Report MR11 2 MT", acViewNormal, acEdit
DoCmd.Close acQuery, "QA Report MR11 2 MT"
strMessage = "Good morning! Here is the new QA report for " & Now() & "."
DoCmd.SendObject acSendTable, strTbl_Name, acFormatXLS, strTo, strSubject, strMessage, False
DoCmd.SetWarnings True
End Sub
I am stumped... I have several make-table queries I run in different Access databases that I run VB code from a button on a form that executes the query, makes the table, and emails it to selected recipients. Is there a way to run and email the query/table from one datadase in another? Here is my attempt so far (failed). I am guessing I need to set the focus somehow to the second db but am not having any luck. Would I need to re-set focus to the main db before I close out of the database? Apologies for not being smarter- I am self taught and cannot get this one.
Private Sub Command1_Click()
Dim strLoc As String, strRun As String
Dim strQry_Name, strTbl_Name As String
Dim strTo As String
Dim strSubject As String
Dim strMessage As String
Dim strDB As String
strQry_Name = "QA Report MR11 2 MT"
strTbl_Name = "MR 2011"
strTo = "Mike"
strSubject = "QA Report: " & Now()
strDB = "Z:\__Mike\VSM_BAC.mdb"
DoCmd.SetWarnings False
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("Z:\__Mike\VSM_BAC.mdb")
accapp.Visible = True
[strDB].SetFocus
DoCmd.OpenQuery "QA Report MR11 2 MT", acViewNormal, acEdit
DoCmd.Close acQuery, "QA Report MR11 2 MT"
strMessage = "Good morning! Here is the new QA report for " & Now() & "."
DoCmd.SendObject acSendTable, strTbl_Name, acFormatXLS, strTo, strSubject, strMessage, False
DoCmd.SetWarnings True
End Sub