Click here to Skip to main content
16,005,120 members
Home / Discussions / Database
   

Database

 
QuestionExport SQL Report to other program such as PDF or EXCEL Pin
NewITMember17-Aug-07 19:29
NewITMember17-Aug-07 19:29 
AnswerRe: Export SQL Report to other program such as PDF or EXCEL Pin
pmarfleet17-Aug-07 23:15
pmarfleet17-Aug-07 23:15 
GeneralRe: Export SQL Report to other program such as PDF or EXCEL Pin
NewITMember17-Aug-07 23:55
NewITMember17-Aug-07 23:55 
GeneralRe: Export SQL Report to other program such as PDF or EXCEL Pin
pmarfleet18-Aug-07 4:16
pmarfleet18-Aug-07 4:16 
GeneralRe: Export SQL Report to other program such as PDF or EXCEL Pin
NewITMember18-Aug-07 21:01
NewITMember18-Aug-07 21:01 
QuestionZipcode stored proc. Pin
tthellebuyck17-Aug-07 8:38
tthellebuyck17-Aug-07 8:38 
AnswerRe: Zipcode stored proc. Pin
andyharman17-Aug-07 10:30
professionalandyharman17-Aug-07 10:30 
QuestionDoCmd.SendObject object assistance needed... [modified] Pin
new_phoenix17-Aug-07 7:46
new_phoenix17-Aug-07 7:46 
Hi, guys. I really need some assistance with the DoCmd.SendObject object in VBA in Microsoft Access. It appears that I am only limited to specific ObjectTypes that does not include an approach to do so dynamically in code.

It appears in code that there are fewer options than there are with the implementation of macros which also permit "Stored Procedures" and "Server Views". Can I send the results of strSQLFQT to the SendObject? You see, I need to loop through two tables at the same time, and for every occurrence of the DISTINCT item in rstMRL there could be many records in rstFQT. I would like to send only the relevent records from rstFQT to each person in rstMRL. Can someone kindly tell me where I am going wrong.

The code I have so far is as follows:

Option Compare Database
Dim db As New DAO.DBEngine
Dim rec As Recordset

Function Email_New()
On Error GoTo Email_New_Err

    DoCmd.OpenQuery "Final Query Test 2", acViewNormal, acReadOnly
    DoCmd.GoToRecord acQuery, "Final Query Test 2", acFirst
    Call SendEmails

Email_New_Exit:
    Exit Function

Email_New_Err:
    MsgBox Error$
    Resume Email_New_Exit

End Function

Function SendEmails()
    On Error GoTo ErrorHandler

    Dim Cnxn As ADODB.Connection
    Dim strConn As String
    Dim rstMRL As ADODB.Recordset
    Dim cmdSQLMRL As ADODB.Command
    Dim strSQLMRL As String
    Dim rstFQT As ADODB.Recordset
    Dim cmdSQLFQT As ADODB.Command
    Dim strSQLFQT As String
    Dim strHoldRecString As String
    Dim strMessage As String
      
    Set Cnxn = New ADODB.Connection
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\GELCO DATABASE\Gelco_USA.mdb;"
    Cnxn.Open strConn
    
    Set cmdSQLMRL = New ADODB.Command
    Set cmdSQLMRL.ActiveConnection = Cnxn
    strSQLMRL = "Select [Rep Number], [Rep ID], [Email Address] " & _
        "FROM [Master Rep List Test] ORDER BY [Rep Number]"
    cmdSQLMRL.CommandType = adCmdUnknown
    cmdSQLMRL.CommandText = strSQLMRL
    Set rstMRL = cmdSQLMRL.Execute()
    rstMRL.MoveFirst
    strHoldRecString = rstMRL![Rep Number]
    
    Set cmdSQLFQT = New ADODB.Command
    Set cmdSQLFQT.ActiveConnection = Cnxn

    ' Attempted Dynamic SQL here...
    strSQLFQT = "SELECT [Confirmation #], [Rep Name], " & _
        "[Report #], [Email Address], [Days Aged] " & _
        "FROM [Final Query Test 2] WHERE [Days Aged] > 30 " & _
        "AND [Rep ID2] = '" & strHoldRecString & "'"
    
    MsgBox strSQLFQT   ' Shows the results

    cmdSQLFQT.CommandText = strSQLFQT
    Set rstFQT = cmdSQLFQT.Execute()
    rstFQT.MoveFirst
    
    
    Do Until rstMRL.EOF
        DoCmd.SendObject acSendQuery, "Final Query Test 2", acFormatXLS, _
            "expense.reports@wrigley.com", , , "Missing Expense Reports", _
            "Hello There, you have some files missing", False
        
        '  Somehow requery the code from the second table here...
        strHoldRecString = rstMRL![Rep Number]
        strSQLFQT = "SELECT [Confirmation #], [Rep Name], " & _
            "[Report #], [Email Address], [Days Aged] " & _
            "FROM [Final Query Test 2] WHERE [Days Aged] > 30 " & _
            "AND [Rep ID2] = '" & strHoldRecString & "'"
        
        rstMRL.MoveNext
    Loop

    
' I am able to loop through the records for each table properly with this code which should identify the fields that I need to include.

    'Do Until rstMRL.EOF
        'strMessage = "Rep Number: " & rstMRL![Rep Number] & _
           ' vbCr & " Rep ID: " & rstMRL![Rep ID] & _
            'vbCr & " Email Address: " & rstMRL![Email Address] & ""
        'MsgBox strMessage
        'rstMRL.MoveNext
    'Loop

    'Do Until rstFQT.EOF
        'strMessage = "Confirmation #: " & rstFQT![Confirmation #] & _
           ' vbCr & " Rep Name: " & rstFQT![Rep Name] & _
            'vbCr & " Report #: " & rstFQT![Report #] & _
           ' vbCr & " Email Address #: " & rstFQT![Email Address] & _
           ' vbCr & " Days Aged: " & rstFQT![Days Aged] & ""
        'MsgBox strMessage
       ' rstFQT.MoveNext
    'Loop


ErrorHandler:
    If Not rstMRL Is Nothing Then
        If rstMRL.State = adStateOpen Then rstMRL.Close
    End If
    Set rstMRL = Nothing
    
    If Not rstFQT Is Nothing Then
        If rstFQT.State = adStateOpen Then rstFQT.Close
    End If
    Set rstFQT = Nothing
    
    If Not Cnxn Is Nothing Then
        If Cnxn.State = adStateOpen Then Cnxn.Close
    End If
    Set Cnxn = Nothing
    
    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Function


Confused | :confused: Confused | :confused: Confused | :confused:



-- modified at 13:58 Friday 17th August, 2007
QuestionCascading Delete Pin
eggie517-Aug-07 7:13
eggie517-Aug-07 7:13 
AnswerRe: Cascading Delete Pin
andyharman17-Aug-07 7:58
professionalandyharman17-Aug-07 7:58 
GeneralRe: Cascading Delete Pin
eggie517-Aug-07 8:07
eggie517-Aug-07 8:07 
Questionsql error # 55030 Pin
deepalititi17-Aug-07 1:09
deepalititi17-Aug-07 1:09 
AnswerRe: sql error # 55030 Pin
andyharman17-Aug-07 1:51
professionalandyharman17-Aug-07 1:51 
QuestionHow to Read Table Data in Image column in SQL SERVER 2000? Pin
Vadlamudi VenuGopal16-Aug-07 22:02
Vadlamudi VenuGopal16-Aug-07 22:02 
AnswerRe: How to Read Table Data in Image column in SQL SERVER 2000? Pin
pmarfleet16-Aug-07 23:24
pmarfleet16-Aug-07 23:24 
AnswerRe: How to Read Table Data in Image column in SQL SERVER 2000? Pin
Colin Angus Mackay16-Aug-07 23:26
Colin Angus Mackay16-Aug-07 23:26 
Questiondisplay a column horizandally Pin
jegastar16-Aug-07 21:11
jegastar16-Aug-07 21:11 
AnswerRe: display a column horizandally Pin
N a v a n e e t h16-Aug-07 23:11
N a v a n e e t h16-Aug-07 23:11 
AnswerRe: display a column horizandally Pin
Senu Gandhi17-Aug-07 23:18
Senu Gandhi17-Aug-07 23:18 
Questionproblem with adding and deleting ADO,also needs a link to resources Pin
king'ori16-Aug-07 20:42
king'ori16-Aug-07 20:42 
Questionproblem with adding and deleting ADO,also needs resources Pin
king'ori16-Aug-07 20:41
king'ori16-Aug-07 20:41 
Questioncase structure in vb.net!!! Pin
Rharzkie16-Aug-07 19:38
Rharzkie16-Aug-07 19:38 
AnswerRe: case structure in vb.net!!! Pin
Colin Angus Mackay16-Aug-07 23:27
Colin Angus Mackay16-Aug-07 23:27 
AnswerRe: case structure in vb.net!!! Pin
andyharman17-Aug-07 2:22
professionalandyharman17-Aug-07 2:22 
AnswerSTOP CROSS-POSTING Pin
leckey17-Aug-07 3:13
leckey17-Aug-07 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.