Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

access vba code

ResolvedVersion 2003

David has attended:
Excel VBA Advanced course
Access VBA course

Access vba code

Could someone explain howthe code below work. I can't understand various bits such as 'Open file for Binary', 'Get #1', 'Print #2' etc. Any help in deciphering this greatly appreciated


Sub output_sc4_file_east_west(mode, scenario)

'macro to read text file and create an SC4 text file
Dim FileContents As String

txt_filename = Left(CurrentDb.Name, Len(CurrentDb.Name) - 4) & "_" & scenario & ".txt"
sc4_filename = Left(CurrentDb.Name, Len(CurrentDb.Name) - 4) & "_" & scenario & "_" & mode & ".SC4"
airport = Left(CurrentProject.Name, 3)

'open txt file and read contents
Open txt_filename For Binary As #1
FileContents = Space(FileLen(txt_filename))
Get #1, , FileContents
Close #1

'remove quotation marks from txt file contents and define sc4 header info
sc4contents = Replace(FileContents, """", "")
sc4header = "ROUTEFILE," & airport & "_" & StrConv(mode, vbProperCase) & "_Routes.rta" & vbCrLf & "SPREADFILE,Departures_Spread.SPD" & vbCrLf & "PRDFILEDIRECTORY,N:\CAEP_NOx_Sample_Problem\INM_PRD_Files"

'create sc4 file
Open sc4_filename For Output As #2
Print #2, sc4header & vbCrLf & sc4contents
Close #2

'delete sc4 txt file
Kill txt_filename

End Sub

RE: access vba code

Hi David

Thanks for the question

As discused, I will investigate and get back to you within the next few days

Regards

Stephen

Mon 18 Jan 2010: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Insert The Current Date

To insert the current date into a Table field or Form Text box use:

Ctrl+Semi-Colon(;)

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.