Results 1 to 9 of 9
  1. #1
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10

    Trigger event with button click

    Hello,



    This is my first post and I am extremely new to Access. I am well adapted to other Office products mainly Excel but I am still testing the waters with Access. My question is very infantile. I have created a very simple form with three buttons and a text box. All I want for one button to be used to select a file, a second button to be linked to vba code that I have already prepared and the third to be a cancel button. If possible I would like the selected file name to appear in the text box and that the 'analysis' button to be disabled until a file is selected.

    I have put the code for selecting a file in a standard vba module since I don't know how to link it to a button and the analysis code is a second module.

    Thank you all in advance.

    AMAS
    Attached Files Attached Files

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    To be able to attach code to a button, you can right click on the button in design view, build event, code builder.

  3. #3
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10
    Thanks. That has gotten me started in the right direction.

  4. #4
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Now to 'disable buttons' you can use vba like

    [control_name].visible=false to hide a control or

    [control_name].locked=true to prevent input, don't forget to unset them when you need the control showing/active though!

    Remember to use events in vb to your advantage, to get you started you might want to take a look at:

    http://office.microsoft.com/en-us/ac...001135957.aspx

  5. #5
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10
    Thanks again. I'm glad that alot of this is similar to Excel vba. I am almost done with this set of hurdles. Buttons are good to go and so is the textbox. My last problem (so far) is getting a dialog box for the user to provide a path and name for the text file. I am using FileDialog to pick a file for analysis. I am assuming there is something similar for saving. Do you have any ideas on what I can use.

  6. #6
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    If you attach the new version of your project i'll take a look and see what I can see.

  7. #7
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10
    Yes, of course. Here is the Access file and a sample text file if you want to give it a run.
    Attached Files Attached Files

  8. #8
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10
    I tried using:

    Code:
    Dim strFilter As String
    Dim strInputFileName As String
    strFilter = ahtAddFilterItem(strFilter, "Text files (*.txt)", "*.TXT")
    strInputFileName = ahtCommonFileOpenSave( _
        Filter:=strFilter, OpenFile:=True, _
        DialogTitle:="Select file name for saving...")
        
    MsgBox strInputFileName
    but it's not invoking a dialog box and the Msgbox is coming back blank.

    Any help is appreciated.

    Thanks.

  9. #9
    AMAS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    10
    Hi,

    OK. Got it working. It turns it's just like the open file dialog box.

    Code:
            Set SaveAsTxt = Application.FileDialog(msoFileDialogSaveAs)
            With SaveAsTxt
                .AllowMultiSelect = False
                .Title = "Save analysis results"
                If .Show = True Then
                    For Each varFile In .SelectedItems
                        DownloadFile = varFile
                    Next
                  Else
                    MsgBox "File not saved. Would you like to try again?"
                    Exit Sub
                End If
            End With

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

Similar Threads

  1. event to trigger after new record
    By richlyn in forum Access
    Replies: 1
    Last Post: 03-02-2012, 10:26 AM
  2. Replies: 2
    Last Post: 07-24-2011, 08:50 PM
  3. Command button click event
    By R_jang in forum Programming
    Replies: 10
    Last Post: 10-29-2010, 10:13 PM
  4. On Click Event For Button On Form
    By Desstro in forum Forms
    Replies: 3
    Last Post: 08-09-2010, 02:36 PM
  5. Trigger subform event
    By tuna in forum Forms
    Replies: 0
    Last Post: 05-09-2010, 06:29 AM

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