This question already has an answer here:
I am trying to practice embedding my code. I created a subroutine called
JrnlHeader to declare variables I will use in another subroutine. I am currently only concerned with one variable named
Header. I would like to know why
Header is empty in subroutine
PrintToTextFile and how I can fix it to be able to use strings declared in JrnlHeader.
Private Sub JrnlHeader() Dim Header As String Dim SeqNo As String Dim SeqVar As String Dim Bu As String Dim BuVar As String Dim JrnlID As String Dim JrnlIDVar As String Dim JrnlDate As String Dim JrnlDateVar As String Dim Descr As String Dim DescrVar As String Dim Ledger As String Dim LedgerVar As String Dim Source As String Dim SourceVar As String Dim CurEff As String Dim Reverse As String Dim AutoLn As String Dim AdjEnt As String Header = "<JRNL_HDR_IMP>" SeqNo = "<SEQNO>" & SeqVar & "</SEQNO>" Bu = "<BUSINESS_UNIT>" & BuVar & "</BUSINESS_UNIT>" JrnlID = "<JOURNAL_ID>" & JrnlIDVar & "</JOURNAL_ID>" JrnlDate = "<JOURNAL_DATE>" & JrnlDateVar & "</JOURNAL_DATE>" Descr = "<DESCR254>" & DescrVar & "</DESCR254>" Ledger = "<LEDGER_GROUP>" & LedgerVar & "</LEDGER_GROUP>" Source = "<SOURCE>" & SourceVar & "</SOURCE>" CurEff = "<CUR_EFFDT>" & JrnlDateVar & "</CUR_EFFDT>" Reverse = "<REVERSAL_CD>N</REVERSAL_CD>" AutoLn = "<AUTO_GEN_LINES>N</AUTO_GEN_LINES>" AdjEnt = "<ADJUSTING_ENTRY>N</ADJUSTING_ENTRY>" End Sub Sub PrintToTextFile() Dim FileNum As Integer JrnlHeader FileNum = FreeFile ' next free filenumber 'Open "C:\Temp\TEXTFILE.TXT" For Output As #FileNum ' creates the new file Open "C:\temp\TEXTFILE.TXT" For Append As #FileNum Print #FileNum, Header Close #FileNum ' close the file End Sub