access vba code

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

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Access vba code

Access vba code

resolvedResolved · Medium Priority · Version 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:

Relationship maps

It is important to create proper relationships between tables. You can use Access to help check your designs and evaluate them by printing them in graphical format to help with design purposes


Click on the Tools menu, click Relationships.
On the File menu, click Print Relationships. View or print as required

View all Access hints and tips


Server loaded in 0.07 secs.