Access Basic Code Example
Function rptPbookWhelp()

Back to Part 5, Write to Text Source File

Function rptPbookWhelp()

Function rptPbookWhelp () As Integer
'This procedure produces two reports printed to file.
'The files produced are the ASCII source files depersn1.src
'and depersn2.src for making the Daniel Phonebook in WinHelp format.
'(NOTE: Source files are used by MiniHelp Help Authoring system.)
'Good instructions for writing to a file were found in ACCESS
'BASIC COOKBOOK, by Chris St. Valentine, p. 164.

'Constant QU is needed in order to print the quotation character to file.
    Const QU = """"
    Dim Filename As String
    Dim FN As Integer
    Dim Datestamp As String
    Dim UtilVart0 As Variant
    Dim UtilVart1 As Variant
    Dim PbookDB As Database
    Dim PbookSet As Recordset

'Set criteria and open a recordset from the Deperson table.
    Set PbookDB = DBEngine.Workspaces(0).Databases(0)
    Set PbookSet = PbookDB.OpenRecordset("DEPERSON", DB_OPEN_DYNASET)

'Set criteria for report output file items.
    Filename = gconPBOOKHLP_A_PATH & "depersn1.src"
    FN = FreeFile     'My shortened version of FileNumber.
    Datestamp = Format(Date, "dd mmmm yyyy")

'Place on screen some progress indicators in case this takes a while.
    DoCmd Hourglass True
    UtilVart0 = SysCmd(SYSCMD_SETSTATUS, "Writing file depersn1.src")

'Create and open the report output file.
    Open Filename For Output As FN

'Start writing these lines to the file header.
Print #FN, ".hpjbitmap danlogo4.wmf"
Print #FN, ".hpjopt title=Phonebook for Daniel Publications"
Print #FN, ".hpjopt compress=medium"
Print #FN, ".hpjopt copyright=Copyright 1996, Daniel Industries"
Print #FN, ".hpjopt report=1"
Print #FN, ".hpjopt warning=3"
Print #FN, ".hpjopt contents=contents"
Print #FN, ".hpjconfig CreateButton("; QU; "btn_exit"; QU; ","; QU; "E&xit"; QU; ","; QU; "Exit()"; QU; ")"
Print #FN, ".hpjconfig CreateButton("; QU; "btn_print"; QU; ","; QU; "&Print"; QU; ","; QU; "Print()"; QU; ")"
Print #FN, ".hpjconfig CreateButton("; QU; "btn_date"; QU; ","; QU; "&Date"; QU; ","; QU; "PI(`depersn1.hlp',`datestamp')"; QU; ")"
Print #FN, ".hpjconfig BrowseButtons()"
Print #FN, ".hpjconfig AppendItem("; QU; "mnu_help"; QU; ","; QU; "mnu_foo"; QU; ","; QU; "&Find a Record"; QU; ", "; QU; "PI(`',`instruc')"; QU; ")"
Print #FN, ".hpjconfig Popupid("; QU; QU; ","; QU; "instruc"; QU; ")"
Print #FN, ".hpjwin main = , , 0, (255,255,255) , (192, 192, 192), 0"
Print #FN,
Print #FN, ".topic instruc"
Print #FN, ".fontsize 11"
Print #FN, "To"
Print #FN, ".bold find a particular phonebook record,"
Print #FN, "click on the"
Print #FN, "\par\pard"
Print #FN, ".bitmap btn_srch.bmp"
Print #FN, " button above."
Print #FN, "\par\pard"
Print #FN, "\sb150"
Print #FN, "In the pop-up "; QU; "Search"; QU; " dialog window, type in the first letters"
Print #FN, "\par\pard"
Print #FN, "of the search term until it appears in the scrollable list."
Print #FN, "\par\pard"
Print #FN, "\sb150"
Print #FN, "Then double-click on the record name, and click on the"
Print #FN, "\par\pard"
Print #FN, ".bitmap btn_goto.bmp"
Print #FN, " button."
Print #FN,
Print #FN, ".topic datestamp"
Print #FN, ".fontsize 11"
Print #FN, "This Help file was last updated on "; Datestamp; "."
Print #FN, "\par\pard"
Print #FN, "\par\pard"
Print #FN, "For corrections, additions, or revisions, notify John Reynolds,"
Print #FN, " Technical Publications, Daniel Instruments, 713-827-4861."
Print #FN,
Print #FN, ".topic contents"
Print #FN, ".title Daniel Electronics Technical Publications Phonebook"
Print #FN, ".browse 0"
Print #FN, "\keepn"
Print #FN,
Print #FN, ".bitmap danlogo4.wmf"
Print #FN, "\par"
Print #FN, "\par"
Print #FN, ".bold Daniel Technical Publications Phonebook"
Print #FN,
Print #FN, "\par\pard"

'Move to the beginning of the recordset.
    PbookSet.MoveFirst

'Start writing these lines for each database record.
    Do Until PbookSet.EOF
Print #FN, "\sb200"
Print #FN, "\li000"
Print #FN, ".fontsize 12"
    UtilVart0 = PbookSet![Lastname]
    UtilVart1 = PbookSet![Firstname]
    If Not IsNull(UtilVart1) Then
        UtilVart0 = UtilVart1 & " " & UtilVart0
    End If
Print #FN, ".bold "; UtilVart0
Print #FN, "\par\pard"
Print #FN, ".fontsize 11"
    If PbookSet![ContactAgent] <> "" Then
Print #FN, "\li300"
Print #FN, "Contact agent: "; PbookSet![ContactAgent]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneBus] <> "" Then
Print #FN, "\li300"
Print #FN, "Work phone: "; PbookSet![PhoneBus]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneAlt] <> "" Then
Print #FN, "\li300"
Print #FN, "Alt. phone: "; PbookSet![PhoneAlt]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneFax] <> "" Then
Print #FN, "\li300"
Print #FN, "FAX phone: "; PbookSet![PhoneFax]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhonePag] <> "" Then
Print #FN, "\li300"
Print #FN, "Page phone: "; PbookSet![PhonePag]
Print #FN, "\par\pard"
    End If
    UtilVart0 = PbookSet![PriAddress] & PbookSet![PriCity] & PbookSet![PriState] & PbookSet![PriZip]
    If Not IsNull(UtilVart0) Then
Print #FN, "\li300"
Print #FN, "\par\pard"
Print #FN, "\li300"
Print #FN, "Address:"
Print #FN, "\par\pard"
        If PbookSet![PriAddress] <> "" Then
Print #FN, "\li1200"
Print #FN, PbookSet![PriAddress]
Print #FN, "\par\pard"
        End If
        UtilVart0 = PbookSet![PriCity] & "   " & PbookSet![PriState] & "   " & PbookSet![PriZip]
        If Not IsNull(UtilVart0) Then
Print #FN, "\li1200"
Print #FN, UtilVart0
Print #FN, "\par\pard"
        End If
    End If
Print #FN, "\par\pard"
Print #FN, "\li300"
Print #FN, "-------- NOTES --------"
Print #FN, "\par\pard"
Print #FN, "\li300"
    If PbookSet![Notes] <> "" Then
Print #FN, PbookSet![Notes]
Print #FN, "\par\pard"
    End If
Print #FN, "\par\pard"

'Move to the next record in the recordset.
    PbookSet.MoveNext
    Loop

'Write these lines to the file end.
Print #FN, "\qc"
Print #FN, ".fontsize 10"
Print #FN, "This table produced by"
Print #FN, ".bold Daniel Industries"
Print #FN, ", "; Datestamp
Print #FN,
Print #FN, ".include depersn2.src"

'Close the file.
Close FN

'Set criteria for report output file items.
    Filename = gconPBOOKHLP_A_PATH & "depersn2.src"
    FN = FreeFile     'My shortened version of FileNumber.

'Return to the beginning of the recordset.
    PbookSet.MoveFirst

'Update progress indicator in status line.
    UtilVart0 = SysCmd(SYSCMD_SETSTATUS, "Writing file depersn2.src")

'Create and open the report output file.
    Open Filename For Output As FN

'Start writing these lines for each database record.
    Do Until PbookSet.EOF
Print #FN, ".topic "; PbookSet![Topic_Name]
Print #FN, ".title "; PbookSet![Lastname]
Print #FN, ".browse "; PbookSet![Browse_Num]
Print #FN, "\par\pard"
Print #FN, "\sb150"
Print #FN, "\li000"
Print #FN, ".fontsize 12"
    If PbookSet![Search_Words] <> "" Then
Print #FN, ".keyword "; PbookSet![Search_Words]
    End If
    UtilVart0 = PbookSet![Lastname]
    UtilVart1 = PbookSet![Firstname]
    If Not IsNull(UtilVart1) Then
        UtilVart0 = UtilVart1 & " " & UtilVart0
    End If
Print #FN, ".bold "; UtilVart0
Print #FN, "\par\pard"
Print #FN, ".fontsize 11"
    If PbookSet![ContactAgent] <> "" Then
Print #FN, "\li300"
Print #FN, "Contact agent: "; PbookSet![ContactAgent]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneBus] <> "" Then
Print #FN, "\li300"
Print #FN, "Work phone: "; PbookSet![PhoneBus]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneAlt] <> "" Then
Print #FN, "\li300"
Print #FN, "Alt. phone: "; PbookSet![PhoneAlt]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhoneFax] <> "" Then
Print #FN, "\li300"
Print #FN, "FAX phone: "; PbookSet![PhoneFax]
Print #FN, "\par\pard"
    End If
    If PbookSet![PhonePag] <> "" Then
Print #FN, "\li300"
Print #FN, "Page phone: "; PbookSet![PhonePag]
Print #FN, "\par\pard"
    End If
    UtilVart0 = PbookSet![PriAddress] & PbookSet![PriCity] & PbookSet![PriState] & PbookSet![PriZip]
    If Not IsNull(UtilVart0) Then
Print #FN, "\li300"
Print #FN, "\par\pard"
Print #FN, "\li300"
Print #FN, "Address:"
Print #FN, "\par\pard"
        If PbookSet![PriAddress] <> "" Then
Print #FN, "\li1200"
Print #FN, PbookSet![PriAddress]
Print #FN, "\par\pard"
        End If
        UtilVart0 = PbookSet![PriCity] & "   " & PbookSet![PriState] & "   " & PbookSet![PriZip]
        If Not IsNull(UtilVart0) Then
Print #FN, "\li1200"
Print #FN, UtilVart0
Print #FN, "\par\pard"
        End If
    End If
Print #FN, "\par\pard"
Print #FN, "\li300"
Print #FN, "-------- NOTES --------"
Print #FN, "\par\pard"
Print #FN, "\li300"
    If PbookSet![Notes] <> "" Then
Print #FN, PbookSet![Notes]
Print #FN, "\par\pard"
    End If
Print #FN, "\par\pard"
Print #FN, "\qc"
Print #FN, ".fontsize 10"
Print #FN, ".bold Daniel Industries"
Print #FN, ", "; Datestamp

'Move to the next record in the recordset.
    PbookSet.MoveNext
    Loop

'Close the File and temporary recordsets and database.
    Close FN
    PbookSet.Close
    PbookDB.Close

'Indicate that things are finished.
    DoCmd Hourglass False
    UtilVart0 = SysCmd(SYSCMD_CLEARSTATUS)
    UtilVart0 = "WinHelp source files " & QU & "depersn1.src" & QU
    UtilVart0 = UtilVart0 & " and " & QU & "depersn2.src" & QU
    UtilVart0 = UtilVart0 & " were successfully written to disk.  "
    UtilVart0 = UtilVart0 & "Look for them in the "
    UtilVart0 = UtilVart0 & gconPBOOKHLP_A_PATH & " directory."
    MsgBox UtilVart0

End Function

Back to Part 5, Write to Text Source File

See also:

©1997 John C. Reynolds III - last updated 1997 November 20
http://www.compassnet.com/jreynold/whdb_4a.htm