Results 1 to 5 of 5
  1. #1
    aspen is offline Competent Performer
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    127

    vba code code to check if microsoft officeDialog open or not

    Hi every one. I have two buttons on a form. one "Pick" to Select a folder by fileDialog and the other "Save" to save the attachment file in the current record to the selected Folder. The two Butons work fine. What I am trying to do is use one button instead of two and delegate the save part to forms on timer event. Like on timer a button is first disabled and use if condition example

    Me. somebutton. disabled = true
    If some button is distabled and filedialog is closed then
    code to save file.
    me. somebutton enabled = false
    -------------------
    My problem is how to vba code to check if Microsoft file dialog is open. and close if it is. Please help



    Thank you

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you are using Application.FileDialog(msoFileDialogFilePicker) to open the dialog then I believe the .Show property will give you what you need. I think it returns 0 if not open.

  3. #3
    aspen is offline Competent Performer
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    127
    Hi Its me thank you very much for the tip. it sounds great. Let me check if it works and then i'll come back. thank you so much.

  4. #4
    aspen is offline Competent Performer
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    127
    Code:
    'Code behind the button
    '-----------------
    ' Grab a copy of the Office file dialog
    With Application.FileDialog(msoFileDialogFolderPicker)
    ' Set the dialog title
    .Title = "Locate a folder to export"
    ' Set the button caption
    .ButtonName = "Choose"
     
    .InitialFileName = "C:\"
    ' Show files as thumbnails
    .InitialView = msoFileDialogViewThumbnail
    ' Show the dialog and test the return
    If .Show = 0 Then
    ' Didn't pick a file - bail
    Exit Sub
    End If
    ' Should be only one filename - grab it
    strPath = Trim(.SelectedItems(1))
    End With
    ' Put focus in a safe place
    '----------------------------
    Me.SaveSelected.Enabled = False
    '----------------------------------
    Me.SetFocus
    Thanks ItsMe thank you so much. I searched google with different phrasing but there is no match. But your solution is so simple. Here is how I applied your solution
    Code:
    'Code on timer event of form
    -=======================
    '=====================================
    If Me.SaveSelected.Enabled = True Then
    Exit Sub
    Else
    '----------------------------------
    If strPath = "" Then
    MsgBox "Please pick a folder to export to."
    Me.AddFile.SetFocus
    Exit Sub
    End If
    If Me.Dirty = True Then Me.Dirty = False 'Save the record
    Dim rstCurrent As DAO.Recordset
    Set rstCurrent = Me.RecordsetClone
    'Make sure there is a record
    If rstCurrent.RecordCount < 0 Then
    MsgBox "Please add a new record by typing text into the field provided."
    rstCurrent.Close
    Set rstCurrent = Nothing
    Exit Sub
    End If
    
    rstCurrent.FindFirst "ID = " & Me.ID
    Call SaveAttachments(rstCurrent, "Files", strPath & "\")
    'rstCurrent.Edit
    'Call RemoveAttachment(rstCurrent, "FileAttach", "Test.txt")    'Use to delete the attachment from the field
    'rstCurrent.Update
    rstCurrent.Close
    Set rstCurrent = Nothing
    MsgBox "The folowing path was used... " & vbCrLf & strPath
    '---------------------------------------------
    Me.SaveSelected.Enabled = True
    End If
    Thanks All of you

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Good deal. There are other things you can do with the dialog box regarding properties for buttons, default directory, etc. Just an FYI

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

Similar Threads

  1. VBA code to check if a record already exists
    By fra90 in forum Programming
    Replies: 3
    Last Post: 11-20-2013, 11:20 AM
  2. Replies: 5
    Last Post: 07-22-2013, 01:11 PM
  3. Replies: 8
    Last Post: 03-14-2011, 09:45 AM
  4. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  5. Code to spell out check amount?
    By spkoest in forum Access
    Replies: 4
    Last Post: 06-16-2009, 07:44 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