I use this to populate a file name in a form so I can reference it in
another
step in the macro.
add an unbound control on the form
add a command button
the code behind the comman button is
Private Sub Command2_Click()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda,
*.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda,
*.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
'Me.Text0 = strFilter & lngFlags
'MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
' Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
' DialogTitle:="Hello! Open Me!")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
Me.Text0 = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3)
' Where Me.text0 equals the name of the unbound text box. Once the text
box is '
' populated you can proceed with the next step
End Sub
:
On Feb 24, 5:53 am, Eric Blitzer
Check for missing references
In your module
Tools/References
:
Thanks for your feedback - it is most helpful.
The second part of your reply makes perfect sense to me (sorry, i'm
still a
bit of a novice with Acces) and I can reference the field
containing the file
in the macro.
However, I can't seem to get the dialog box to work.
I tried using your code and associating it with an command button
on my
form. This didn't work. If I insert a comman button and associate
your code
with the OnClick function of the button, I get the following
message:
Compile Error: Sub of Function not defined.
[The AddFilterItem text is highligted - i presum I need to enter
something
relating to my own database here?]
Do I need to create a seperate form for the dialog box? If so,
where should
I insert the code detailed
athttp://
www.mvps.org/access/api/api0001.htm?
Many thanks for your help.
David
:
You can't do that from a macro. You could use the file dialog
box on a form
and reference the file name found in your macro.
For file dialog box on a form go to
http://www.mvps.org/access/api/api0001.htm
To reference the control name you added on the form from the file
dialog box
where the file name in the macro use
=[Forms]![NameOfForm]![NameOfTextbox]
:
I've set up a transfer spreadsheet macro to import data
automatically into my
Access database.
In the macro section, I have to enter a file name...
I know how to get a lookup box to ask the user to manually
enter the
filename. However, what I would prefer is to give the user the
opportunity to
BROWSE for the file rather than have to manually enter the path
for the file.
Is there a way this can be done?
Any help would be gratefully appreciated.
David Hawes

- Hide quoted text -
- Show quoted text -
The code works properly. However, if the module to save the file does
not work properly. The variable myStrFilter is not defined. The code
executed is below;
strFilter = ahtAddFilterItem(myStrFilter, "Excel Files (*.xls)",
"*.xls")
strSaveFileName = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
Also, when execute the open function is looks like it works but the
file is not actually open. Don't understand. Please guidance. The
overall code is very interesting.
Your response will be appreciated.