SET default for opening location to choise an attachment

drtopserv
drtopserv used Ask the Experts™
on
Hi,
How can i set a default location for where to choise a file when i click to choise afile for an attachment field.
also can i limit adding only one file to an attachment of a field.
i need to do it through vba code if possible.
i have access 2010
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
- this need a changes to the registry in the following HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders under Personal key
- read further here:
http://support.microsoft.com/kb/252732
Top Expert 2011
Commented:
- sorry, the above is for outlook. got confused i thought it was for Outlook, reading it from Office zone :)
Top Expert 2011
Commented:
hi again,
- in the following code, FileDialog object is used to open the dialog box and set the default folder to c:\temp when it shows.
- refer to the documentation on other properties of the object: http://msdn.microsoft.com/en-us/library/aa163948(v=office.10).aspx


Sub FormCaption()

   Dim fDialog As Object
   Dim varFile As Variant
   Set fDialog = Application.FileDialog(3)
 
   With fDialog

      ' set the default folder to open
      .InitialFileName = "c:\temp"
      
      ' set the title of the dialog box. '
      .Title = "Please select one or more files"

      ' add our own filter'
      .Filters.Clear
      .Filters.Add "Access Databases", "*.MDB"
      .Filters.Add "All Files", "*.*"

      ' show the dialog box.
      If .Show = True Then

      Else
         MsgBox "You clicked Cancel"
      End If
   End With
End Sub
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2011

Commented:
- you need to have References sets on Microsoft Access xx Object Library (from menu > Tools > References)

Author

Commented:
does this works in a field type attachment?
how can i do it through a form when the field is an attachment field, may an sample?
also how can i set it to valid only for 1 file to upload .
Top Expert 2011

Commented:
"does this works in a field type attachment? how can i do it through a form when the field is an attachment field, may an sample"

- i've never use fileDialog or attachment before. i hope you can further work based on the sample and documentation:
http://office.microsoft.com/en-us/access-help/HV080757678.aspx


' get selected filename
 If .Show = True Then
         returnValue = .SelectedItems
         'OR 
         returnValue = .SelectedItems.Item(1)
Else
         MsgBox "You clicked Cancel"
End If

"also how can i set it to valid only for 1 file to upload "
' only 1 file to select. put this within the With fDialog before the filters

.AllowMultiSelect = False

Author

Commented:
bro, this not working !!

Author

Commented:
When i click on the pin apear when i hover the mouse on the field typed attachment and got a dialog window for which i have to choose a file, i`m not getting the defualt folder location by attaching ur code to control(field) in the form
Top Expert 2011

Commented:

- add the following code to the attachment control's "On Enter" event:

Dim strDefaultFolder As String
strDefaultFolder = [The folder you want]
Application.SetOption "Default Database Directory", strDefaultFolder

- this is a solution on default folder for attachment on EE:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_26688072.html

Author

Commented:
Wow,this Works!! , but how can i limit only 1 file to upload in there?
Top Expert 2011

Commented:
- i can't find any arguments related to limit number of file in argument list as per the following link. maybe you can use Validation Rule but i've never done such rule so i could not help further on this:

http://support.microsoft.com/kb/216888 

Author

Commented:
I`ll check it now.
can i edit the path of the files attached through vba code?
Top Expert 2011

Commented:
- sorry for the late reply. i miss-look the EE alert on this question.
- i am not sure about this as i can't test this now. but since you bound it to the attachment control, i can't be sure if you can changed it via vba. Other experts might have opinion on this.

Author

Commented:
thnx anyway.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial