Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    6

    Unanswered: VB code from wizard activity

    How can I see the visual basic code that is generated when I set up a query, form or other action in Access?

    Thanks

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    To view the vba select statement in a query, while in design view of the query, below the File in the upper left you should see a drop down where you can select "Design View" or "SQL View" (plus some other options). Select "SQL View" to view the vba select statement (after you've added a table to the query and dragged some fields down to the grid below.) Also try designing a new query and going through the wizard (ie..Find Duplicates Query Wizard or Find Unmatched Query Wizard...etc..) The wizard will walk you through steps on setting up the query. Once you've finished the wizard, view the "SQL View" again to see the select statement the query wizard created. Also note that in design view of the query, you can select different query types (ie..Query -> Select Query, Update Query, Append Query, etc...etc...)

    To view the vba code in a form, show the properties (ie. View -> Properties) while in design view of the form, click the events tab, select any event (ie. On Open...), click the dropdown at the right of this line (next to the ...), select [Event Procedure], and then click the ... - this then takes you to the vba code you write for when the form Opens (ie. On Open event). Or you can simply select View -> Code to see the coding in the form. In some examples from the Code Bank, you might notice code like the following in a form (for example some code someone wrote in the On Close event of the form):

    Private Sub Form_Close()
    Application.Quit
    End Sub

    The example code above is saying..."Quit the application when the Form closes." Each vba code for an event usually begins with a "Private..." and ends with an "End Sub" Looking at the Events tab in the properties in design view of the form, you will see [Event Procedure] for any event lines which have code for that event. Again clicking the ... takes you to the vba code for that event. NOTE: When you're viewing the vba code, you need to View -> Object to switch back to design view of the form (or click the upper right X to close the vba code view and go back to the object/design view of the form.) Also Note that if you click the upper right X in the vba code, it closes the vba code and goes to design view BUT if you click the upper right X while in design view of the form, Access exits! This is very easy to get mixed up and you may find yourself closing Access unexpectedly because you accidently clicked the upper right X while in design view (verses vba code view).

    Notice that you can also write code for other events of the form (ie. On Current, Before Insert, After Insert, etc..etc..).

    Add a text box control to the form (ie. View -> ToolBar -> Toolbox if it's not showing to see what kind of controls you can add to a form - hold the mouse over each control to see what type each one is which will show as you put the mouse over the control...ie..Label, Text Box, Option Group..etc...etc..) Click on the text box control on the Toolbox and then drag a box on the form. Then click on the text box you just made (viewing the properties of it ...View -> Properties if it's not showing) and you will notice that you can also write code against events for that text box (ie..Before Update, After Update, On Dirty, On Undo, etc..etc..) You click the dropdown for that event and select [Event Procedure] again and then click the ... to the right of the dropdown. You can write code in events against other types of controls of the ToolBox you put on the form (see Help for ToolBox controls.)

    Using the Toolbox again, there is also a Command button. Click this and draw a square on the form, a wizard will appear where you can select from some options (ie..Record Navigation -> Find Next or -> Find Record, etc...etc... or Record Operations -> Add a New Record or -> Delete a Record, etc....etc..., Form Operations, -> etc..etc..) Once you go through the wizard (selecting one of the wizard items), then click on the button while still in design view of the form (again viewing the properties, events tab) and notice there is [Event Procedure] for the On Click. Click the ... to the right of that line to see what the wizard created for vba code depending on what you told the button to do via the wizard.

    If you want help on what each event does, click on that event line and push the F1 key.

    Try downloading some examples in the MSAccess Code Bank and notice some of the events programmed in for some of the forms or other controls in any of the example downloads.

    Hope that helps.
    Last edited by pkstormy; 08-23-07 at 23:56.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    6
    Quote Originally Posted by pkstormy

    Hope that helps.
    Thanks, but I already knew how to access SQL code, and I know that one can write additional code for events.

    My question is can I see the underlying Visual Basic code that I assume would be generated by running a wizard like a query, create a table, build a form, etc etc.


    Joe

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Visual Basic code? In an MS Access question (which is the forum you're in), you can see the Visual Basic for Applications code.! Although this code is similiar to Visual Basic code, there are differences.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    I moved the post here, from the VB forum, as it appeared to be strictly dealing with Access/VBA.

    As far as I know, there IS no VB code generated within access when these wizards are run. These wizards are just apps that simply collect the required information, and executes machine code to build the requested database objects.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  6. #6
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    6
    Quote Originally Posted by loquin
    I moved the post here, from the VB forum, as it appeared to be strictly dealing with Access/VBA.

    As far as I know, there IS no VB code generated within access when these wizards are run. These wizards are just apps that simply collect the required information, and executes machine code to build the requested database objects.
    Thanks Loquin, for answering my question, regardless of where it was posted. Typically, the relationship between Office apps, VBa, VB and MS Office Macros are highly interrelated, yet I've been hard put to actually discern where one stops and the other starts.

    Only my 3rd or 4th post here on DBforums, and I already know why you are the SUPER moderator!

    Thanks,

    Joe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •