Results 1 to 3 of 3
  1. #1
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22

    Form command button to do something/call function

    I have created a basic form in access that has a couple of buttons and text fields. I want the button to do something along the lines of when I click it, it should bring up a browse file dialog and when I select a file, change the text field to the path of the file.



    My question is how can I program this? Specifically, do I create a module that goes like?

    Code:
    sub command1_onClick()
      ...bla bla...
    end sub
    Or are forms programmed differently? How can I tie a function to a button?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See if this gets you started:

    http://access.mvps.org/access/api/api0001.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22
    I was able to sort of get it working another way:

    Code:
    Private Sub browseDataButton_Click()
    
        Dim dlg As Office.FileDialog
    
        Set dlg = Application.FileDialog(msoFileDialogFilePicker)
        
        dlg.Title = "Select Excel Spreadsheet to import"
        dlg.AllowMultiSelect = False
        If dlg.Show = -1 Then
            dataPath = dlg.InitialFileName
            MsgBox dlg.InitialFileName
            Me!browseDataPath = dlg.InitialFileName
            
        End If
    
    End Sub
    I'm able to get the directory where the file is, but does not append the name of the file to the directory.
    For example if blabla.xls is on the C drive, MsgBox will popup "C:\".
    How do I make popup "C:\blabla.xls" (or whatever the xls file may be for that matter)?

    Thanks

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

Similar Threads

  1. Replies: 13
    Last Post: 07-27-2011, 12:38 PM
  2. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Export Command Button in Form
    By jjmartinson in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 01:28 AM
  5. Adding Command Button To Form
    By uneek78 in forum Forms
    Replies: 7
    Last Post: 03-27-2009, 07:43 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