Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

VBA Module Object and Methods

VBA Module Object have several interesting methods and properties.  Last week we have seen how to insert a Click Event Procedure in a Form Module with a Function. You can find this blog post here.

I don’t say that the frm.Module.CreateEventProc() method, that we have tried, was an easy approach to write a one line statement in a Form Module.  But, trying something different is always exciting in programming like exploring the unknown.  After all, it is there as part of the Application to explore and learn. 

Today we will try an alternative and simple method for the same example we have tried last week.  That is to write all the program lines in a text file and load that program directly into the Form Module.

If you have tried last week’s example we can use the same ‘Sample’ Form for today’s trial run,  or do the following to get prepared:

  1. Open a new Form in Design View.
  2. Create a Command Button on the Detail Section of the Form.
  3. While the Command Button is in selected state display it’s Property Sheet (F4 or ALT+Enter).
  4. Change the Name Property Value to cmdRun and the Caption Property Value to Run Report.
  5. Save the Form with the name Sample.
  6. If you have last week’s Sample form then open it in Design View.
  7. Display the Form Module, remove the existing program lines and save the Form.
  8. Open Notepad, copy and paste the following program lines into Notepad and save it as c:\windows\temp\vbaprg.txt:
    Private Sub cmdRun_Click()
    
        DoCmd.OpenReport "myReport", acViewPreview
    
    End Sub
  9. Replace the report name "myReport" with one of your own Report Name from the database.
  10. Open a Standard VBA Module, copy and paste the following main program into the Standard Module:
    Public Function LoadFromTextFile()
    Dim frm As Form, frmName As String, ctrlName As String
    
    frmName = "Sample"
    'ctrlName = "cmdRun"
    
    'Open the form in design view
    DoCmd.OpenForm frmName, acDesign
    
    'define the form object
    Set frm = Forms(frmName)
    
    'call the form's Module Object's AddFromFile() method
    'to read the program from the text file
    'and insert them into the Form Module
    frm.Module.AddFromFile "c:\windows\temp\vbaprg.txt"
    
    'Save and close the form with the code
    DoCmd.Close acForm, frmName, acSaveYes
    
    'Open the form in Normal view
    DoCmd.OpenForm frmName, acNormal
    
    End Function
  11. Place the cursor in the middle of the Code and press F5 to run the Code.
  12. Press ALT+F11 to display the Database window with the Sample Form open.
  13. Click on the Command Button to open the Report in print preview.
  14. Close the Report.
  15. Change the Sample Form in Design View.
  16. Open the form module and check for the program lines we have loaded from the vbaprg.txt file.
Technorati Tags: ,,
Share:

No comments:

Post a Comment

Comments are subject to moderation before publishing.

Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

http://clicky.com/101199826
Blog Directory Visit blogadda.com to discover Indian blogs

Search

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Class Module Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Array Queries msaccess reports External Links msaccess tips Accesstips Downloads Objects Property Menus and Toolbars Controls Event MsaccessLinks Process Controls Art Work Collection Object WithEvents msaccess How Tos Combo Boxes Graph Charts List Boxes VBA msaccessQuery Command Buttons Command Button Data Dictionary Object Emails and Alerts Form Query RaiseEvent Report Calculation Custom Wizards DOS Commands Data Type ms-access functions msaccess functions msaccess graphs msaccess reporttricks Custom Functions Item Object Reference msaccessprocess security advanced Access Security Add Field Type Fields Form Instances Key Macros Menus SubForm Top Values Variables msaccess email msaccess menus progressmeter Access2007 Auto-Number Copy Excel Expression Join Methods Microsoft Numbering System Records Recordset Security Split Table Time Difference Utility Workgroup Wrapper Classes database function ms-access msaccess wizards reference text tutorial vba code Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif msaccess msaccess alerts pdf files restore switch toolbar updating upload

Featured Post

ROUNDDOWN Function of Excel

We have introduced ROUNDUP() Function of Excel in Microsoft Access earlier.  It works like ROUND() Function except that the number is alway...

Labels

Blog Archive

Recent Posts