Results 1 to 9 of 9
  1. #1
    bkelly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17

    How to run VBA procedure

    Windows XP, Access 2003, neophyte Access programmer



    When writing VBA in Excel, pressing F5 would run the procedure where the cursor was located. In Access it opens a menu and asks which procedure I want to run. Although I have saved the procedure, it does not show up in the menu.

    How do I just run the procedure I am editing?
    How do I add my procedure to <something/somewhere> so it will show up in the list of functions to run?

    Second, and I don't know if this is related:
    I copied this code fragment directly from the VBA help function to start up a file open dialog box and put it in the click event for a button:
    Code:
    Private Sub btnImportData_Click()
    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog( _
        FileDialogType:=msoFileDialogOpen)
    With dlgOpen
        .AllowMultiSelect = True
        .Show
    End With
    End Sub
    When I try to run it Access pops up a dialog error box that says:
    User-defined type not defined
    This is right from the help function. FileDialog is not my data type, it should be already defined. What do I need to get an open file dialog box?

    Thank you for your time.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In order to execute code in a form, the form needs to be running. Put a breakpoint in the code if you want to drop into the debugger.

  3. #3
    bkelly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17

    must use form control to start VBA?

    If I understand you correctly, I must use a control such as a button to start a VBA procedure.

    I suspected that and created a form with just a single button and added the proceedure to the Click event. Is this the correct way?

    I have done some more searching and am reaching the conclusion that VBA in Access is not able to use the standard open file dialog box. Is this true?

    Following up on that assumption: A few places referenced something about an Access Developers Edition (or Addition) that provides this ability. My searches did not return any solid. I found some stuff about Visual Studio developer stuff, but nothing that said it was a developer's kit for Microsoft Access. Have I reached the right conclusion and is there such a thing?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You are on the right track for executing code in a form. Public procedures in a Standard Module can be executed directly from the Immediate window. <ctrl>G
    Finding the developer extensions for ac2003 could be tough and I do not believe it offers what you are talking about anyway.

  5. #5
    bkelly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17
    So I surmise that I cannot use the Open File Dialog Box from Access. That really is a pity and quite surprising.

    Regardless, you have answered my questions so Thank You for your time.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by bkelly View Post
    So I surmise that I cannot use the Open File Dialog Box from Access. That really is a pity and quite surprising.
    On the contrary but most of us prefer to use the API.

  7. #7
    bkelly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17
    I found that one earlier today. Looks to me like its building its own dialog box rather than using the simple function:
    Code:
    Set dlgOpen = Application.FileDialog( _
        FileDialogType:=msoFileDialogOpen)
    I'll save that link but for now will work on some code to read data from a text file and fill in records in my database. Then I can return to this concept.
    Thanks again for your time.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Just an FYI: the common control can have versioning issues and the API does not.

  9. #9
    bkelly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17
    I wasn't aware of that.
    Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. how to call a sub procedure?
    By dollygg in forum Access
    Replies: 1
    Last Post: 08-18-2009, 05:10 AM
  2. Troubleshoot NotInList Event Procedure
    By skyrise in forum Programming
    Replies: 4
    Last Post: 02-23-2009, 06:06 PM
  3. stored procedure return value to access form
    By rbw940 in forum Programming
    Replies: 0
    Last Post: 10-13-2008, 01:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums