Results 1 to 11 of 11
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365

    output debug.print window


    Hi Guy's is there an easy way to output the results from the immediate window to ie: .docx or Excel or access report ?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,557
    Not that I am aware of?
    You could just copy and paste?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Those results from the immediate window must be coming from somewhere, so what are you debug.printing?
    You can probably write it to a text file.

    Code:
    Sub sCreateATextFile(Destination As String, Optional Txt As String = "xxx")
    
    
        Dim fso As FileSystemObject, ts As TextStream
    
    
        'Create the FileSystemObject
        Set fso = New FileSystemObject
        'Create the TextStream
        Set ts = fso.CreateTextFile(Destination & "TestMe.txt")
        'Write a line ending with NewLine to text file
        ts.Write Txt
        'Close the file
        ts.Close
    
    
        'Clean up memory
        Set fso = Nothing
        Set ts = Nothing
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Hi Moke123, thank you so much for your reply, the line highlighted in red gives me appointment results in the immediate window, If I try and make a variable for it instead, it won't let me do that.....

    Code:
    If varOpt = "7" Then     
        myStart = InputBox("Enter Start Date ?" & vbNewLine & vbNewLine & "Default Is Today", "ENTER START DATE", Date)
        iMonths = InputBox("Enter How Many Months From Now You Want To Search Appointments ?" & vbNewLine & vbNewLine & _
        "Default Is 3 Months", "ENTER MONTHS", 3)
        
        myEnd = DateAdd("m", iMonths, myStart)
        
       ' Debug.Print "Start:", myStart
       ' Debug.Print "End:", myEnd
         
        Set olobj = CreateObject("Outlook.Application")
        Set oloappt = olobj.CreateItem(olAppointmentItem)
        
        Set oCalendar = oloappt.Session.GetDefaultFolder(olFolderCalendar)
        Set oItems = oCalendar.Items
         
        oItems.IncludeRecurrences = True
        oItems.Sort "[Start]"
         
        strRestriction = "[Start] <= '" & Format$(myEnd, "mm/dd/yyyy hh:mm AMPM") _
        & "' AND [End] >= '" & Format(myStart, "mm/dd/yyyy hh:mm AMPM") & "'"
        
       ' Debug.Print strRestriction
         
        'Restrict the Items collection
        Set oResItems = oItems.Restrict(strRestriction)
         
        For Each oAppt In oResItems
            Debug.Print "Appointment Date: " & oAppt.Start, "Appointmnet Subject: " & oAppt.subject
        
        Next
        
    End If
    I am not able to try something like

    strMSG ="Appointment Date: " & oAppt.Start, "Appointmnet Subject: " & oAppt.subject

    MsgBox(strMSG)

    Or an output

    I have made a template file called > Outlook Appointments.docx in my word docs folder, if i could output to there instead would be fab

    however, i will look at your FSystem option also



  5. #5
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    @Moke123 is your Sub a public sub in a module or can I Dim within the same procedure ?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,557
    Dave,
    Instead of Debug.Print you would ts.Write whatever it is you want to see.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Thanks WGM, yes as per Moke123 suggestion, coming back to this later but much appreciate your input

  8. #8
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    I have tried adding Moke123 as a public sub in my Public Sub modules

    then changed debug.print to ts.write but it's returning Object required, i can't be reading / understanding ts.write perhaps as i haven't used before

    Public Sub

    Code:
    Option Compare DatabaseOption Explicit
    
    
     Public Sub sCreateATextFile(Destination As String, Optional Txt As String = "xxx")
    
    
    
    
        Dim fso As FileSystemObject, ts As TextStream
    
    
    
    
        'Create the FileSystemObject
        Set fso = New FileSystemObject
        'Create the TextStream
        Set ts = fso.CreateTextFile(Destination & "TestMe.txt")
        'Write a line ending with NewLine to text file
        ts.Write Txt
        'Close the file
        ts.Close
    
    
    
    
        'Clean up memory
        Set fso = Nothing
        Set ts = Nothing
    End Sub
    Code:
    If varOpt = "7" Then     
        myStart = InputBox("Enter Start Date ?" & vbNewLine & vbNewLine & "Default Is Today", "ENTER START DATE", Date)
        iMonths = InputBox("Enter How Many Months From Now You Want To Search Appointments ?" & vbNewLine & vbNewLine & _
        "Default Is 3 Months", "ENTER MONTHS", 3)
        
        myEnd = DateAdd("m", iMonths, myStart)
        
       ' Debug.Print "Start:", myStart
       ' Debug.Print "End:", myEnd
         
        Set olobj = CreateObject("Outlook.Application")
        Set oloappt = olobj.CreateItem(olAppointmentItem)
        
        Set oCalendar = oloappt.Session.GetDefaultFolder(olFolderCalendar)
        Set oItems = oCalendar.Items
         
        oItems.IncludeRecurrences = True
        oItems.Sort "[Start]"
         
        strRestriction = "[Start] <= '" & Format$(myEnd, "mm/dd/yyyy hh:mm AMPM") _
        & "' AND [End] >= '" & Format(myStart, "mm/dd/yyyy hh:mm AMPM") & "'"
        
       ' Debug.Print strRestriction
         
        'Restrict the Items collection
        Set oResItems = oItems.Restrict(strRestriction)
         
        For Each oAppt In oResItems
            ts.Write "Appointment Date: " & oAppt.Start, "Appointmnet Subject: " & oAppt.subject OBJECT REQUIRED
        
        Next
        
    End If

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You need to use call the function Moke provided :

    Code:
    sCreateATextFile("C:\MyTextFiles\DebugOutput.txt", "Appointment Date: " & oAppt.Start, "Appointmnet Subject: " & oAppt.subject)
    Personally I would put the destination filepath and the captured text into variables and pass them into the function/sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    try something like . . .

    Code:
    For Each oAppt In oResItems
            strOut = Strout & "Appointment Date: " & oAppt.Start, "Appointmnet Subject: " & oAppt.subject  & vbnewline
    Next
    
    sCreateATextFile "C:\MyTextFiles\DebugOutput.txt", strOut
    If you want to do it within the loop you'd need to use an append procedure.

    something like...
    Code:
    Sub OpenTextFileAppend(sTextFilePath As String)
        ' Must add reference to Tools > References > Microsoft Scripting Runtime
        ' (1) Open an instance of the FileSystemObject.
        ' (2) Open an instance of the FileSystemObject TextStream.
        ' (3) Append lines to the TextStream object.
        ' (4) Close the TextStream object.
    
    
        Dim fso As Scripting.FileSystemObject
        Dim tsTxtFile As Scripting.TextStream
        
        ' (1) Open an instance of the FileSystemObject.
        Set fso = New Scripting.FileSystemObject
        
        ' (2) Open an instance of the FileSystemObject TextStream.
        Set tsTxtFile = fso.OpenTextFile(sTextFilePath, ForAppending, False, TristateMixed)
            
        With tsTxtFile
        
            ' (3) Append lines to the TextStream object.
            '.WriteBlankLines 6
            If .Line = 2 Then .Skip 10
            .WriteLine "[1] Appended at the end of the TextStream xxx"
             If .Line <> 1 Then .Skip 2
            .WriteLine "[1] Appended at the end of the TextStream xxx"
            
            ' (4) Close the TextStream object.
            .Close
            
        End With
        
        Set fso = Nothing
    
    
    End Sub
    Doing it the first way is probably easier.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,365
    Thank you guy's i need more time to understand the ts.write option which i will do, however, i have managed to output to an email body

    Code:
    If varOpt = "7" Then     
        myStart = InputBox("Enter Start Date ?" & vbNewLine & vbNewLine & "Default Is Today", "ENTER START DATE", Date)
        iMonths = InputBox("Enter How Many Months From Now You Want To Search Appointments ?" & vbNewLine & vbNewLine & _
        "Default Is 3 Months", "ENTER MONTHS", 3)
        
        myEnd = DateAdd("m", iMonths, myStart)
    
    
        Set olobj = CreateObject("Outlook.Application")
        Set oloappt = olobj.CreateItem(olAppointmentItem)
        
        Set oCalendar = oloappt.Session.GetDefaultFolder(olFolderCalendar)
        Set oItems = oCalendar.Items
         
        oItems.IncludeRecurrences = True
        oItems.Sort "[Start]"
         
        strRestriction = "[Start] <= '" & Format$(myEnd, "mm/dd/yyyy hh:mm AMPM") _
        & "' AND [End] >= '" & Format(myStart, "mm/dd/yyyy hh:mm AMPM") & "'"
        
        Set oResItems = oItems.Restrict(strRestriction)
         
        For Each oAppt In oResItems
            
                strOut = strOut & oAppt.Start & " " & oAppt.subject & "|"
        Next
        
        Set MyItem = myApp.CreateItem(olMailItem)
        Set OutAccount = myApp.Session.Accounts.Item(1)
        
            With MyItem
            .To = ""
            .subject = "Appointments"
            .HTMLBody = "Appointments Between " & Format(myStart, "dddd-dd-mmmm-yyyy") & " And " & Format(myEnd, "dddd-dd-mmmm-yyyy") & "<br>" & "<br>" & _
            strTable & "<br>" & Replace(strOut, "|", "<br>") & "<br>" & strLine & "<br>" & strTableEnd
            .SendUsingAccount = OutAccount
            .Display
            
        End With
            
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-07-2022, 02:05 AM
  2. Debug.Print Stored SQL Querys
    By Noob in forum Access
    Replies: 7
    Last Post: 07-13-2016, 04:57 PM
  3. Replies: 13
    Last Post: 07-09-2013, 07:05 PM
  4. Automatically Closing Print Preview Window
    By chris.williams in forum Reports
    Replies: 5
    Last Post: 08-07-2012, 05:02 PM
  5. Output file print in mangal font (hindi language)
    By Naresh in forum Programming
    Replies: 0
    Last Post: 06-21-2012, 12:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums