MACRO QUERY - how to enable user to "browse" for the "file name"

D

DavidHawes

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 :)
 
E

Eric Blitzer

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]
 
D

DavidHawes

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 at http://www.mvps.org/access/api/api0001.htm?

Many thanks for your help.

David

Eric Blitzer said:
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]

DavidHawes said:
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 :)
 
E

Eric Blitzer

Check for missing references
In your module
Tools/References

DavidHawes said:
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 at http://www.mvps.org/access/api/api0001.htm?

Many thanks for your help.

David

Eric Blitzer said:
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]

DavidHawes said:
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 :)
 
L

Luis

Check for missing references
In your module
Tools/References



DavidHawes said:
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.

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.
 
E

Eric Blitzer

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

Luis said:
Check for missing references
In your module
Tools/References



DavidHawes said:
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.

"Eric Blitzer" wrote:
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]
"DavidHawes" wrote:
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.
 
D

DavidHawes

Many thanks for this.

I am with you now and understand your code below.

Which reference do I need to add in the cisual basic module to enable the
"ahtAddFilterItem" function to operate?

Many thanks for your assistance,

David HAwes

Eric Blitzer said:
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

Luis said:
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.
 
D

Douglas J. Steele

No reference need be added. Ensure that you copied that function from
http://www.mvps.org/access/api/api0001.htm at "The Access Web". (Copy
everything in the shaded area between Code Start and Code End)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


DavidHawes said:
Many thanks for this.

I am with you now and understand your code below.

Which reference do I need to add in the cisual basic module to enable the
"ahtAddFilterItem" function to operate?

Many thanks for your assistance,

David HAwes

Eric Blitzer said:
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

Luis said:
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.
 
D

DavidHawes

BINGO!

Massive thanks to you both.

David

Douglas J. Steele said:
No reference need be added. Ensure that you copied that function from
http://www.mvps.org/access/api/api0001.htm at "The Access Web". (Copy
everything in the shaded area between Code Start and Code End)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


DavidHawes said:
Many thanks for this.

I am with you now and understand your code below.

Which reference do I need to add in the cisual basic module to enable the
"ahtAddFilterItem" function to operate?

Many thanks for your assistance,

David HAwes

Eric Blitzer said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top