Browse window in form.

G

Guest

I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
G

Guest

Paste the code into it's own standard module. I call mine modCommonDialog.
Delete those rows at the bottom that are not code and not comments, or just
make them comment lines. As to using it, here is an example where I use it:

'Set filter to show only Excel spreadsheets
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)")
'Hides the Read Only Check Box on the Dialog box
lngFlags = ahtOFN_HIDEREADONLY

strCurrMonth = Me.cboPeriod.Column(1)
strCurrYear = Me.txtCurrYear
'Get the File Name To Save
strDefaultDir = "\\rsltx1-bm01\busmgmt\Vought " & strCurrYear & "\" &
strCurrYear _
& " Actuals\" & strCurrMonth & "\"
varGetFileName = "Vought Invoice " & strCurrMonth & " " & strCurrYear &
".xls"

varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _
strDefaultDir, "Excel Spreadsheets (*.xls) *.xls", , _
"xls", varGetFileName, "Import Adjusted Actuals", , True)
Me.Repaint
If varGetFileName = "" Then 'User Clicked CANCEL
GoTo LoadAdjustedActuals_Exit
End If
 
G

Guest

Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.
 
G

Guest

Thanks for the step-by-step. That's exactly what I needed, it works great.

jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
G

Guest

Hi,

I saw your procedure, and I tried to do the same thing. I kept getting a

"compile Error, method or data member not found"

Can you help? thank you


jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
G

Guest

This works nicely, but I'm just curious. For my application, I want to be
able to browse and insert only a folder for all export files to go into that
pertain to that show. Is there any way to do that other than selecting a
file and then taking the file name off the end? I have a lot of functions
that export data for merges, etc., and it would be nice to be able to have
the system select which folder based on the Show ID rather than having to
change them all manually every year. Once I have the folder in my text box,
I know how to get it into my dialog boxes and from there into my procedures,
but getting just the folder into the text box is a little tricky. TNX
--
Amy E. Baggott

"I''m going crazy and I''m taking all of you with me!" -- Linda Grayson


jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
S

Sietske

Thanks from me too. It works great!

jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
H

hfrupn

I to found this to work well but I have two issues that I just can’t seem to
fix.
(1) The text box is set for a hyperlink but when the file path populates the
hyperlink does not work. However if I paste the path into the text box it
works fine.
(2) If I have returned the file path and then search again without selecting
a file. I then press the cancel button the file path already entered into the
text box is deleted.
Is there a way to fix these?
Any help is appreciated.

Nick


jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
H

hfrupn

I to found this to work well but I have two issues that I just can’t seem to
fix.
(1) The text box is set for a hyperlink but when the file path populates the
hyperlink does not work. However if I paste the path into the text box it
works fine.
(2) If I have returned the file path and then search again without selecting
a file. I then press the cancel button the file path already entered into the
text box is deleted.
Is there a way to fix these?
Any help is appreciated.

Nick


jmonty said:
Go to the webpage: http://www.mvps.org/access/api/api0001.htm
Copy only the shaded area which starts with:
'***************** Code Start **************
and ends with:
'************** Code End *****************
Be sure to include the leading single quotes ['].

Open your Access Database to the Modules tab. Click New.
Paste the code into it.
Change the line Function TestIt() to the following:
Function TestIt() As String
Then change the line:
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
to
TestIt = ahtCommonFileOpenSave(InitialDir:="C:\", _
Save it.
Open Your form in design mode. Add a button and cancel the wizard. Right
click on the button and select Build Event, then choose Code Builder. In the
newly created sub add the code something similar to:

Private Sub Command2_Click()
Me.Text0 = TestIt()
End Sub

where Command2 is the name for the button and Text0 is the name of your
textbox.
Save all and close the VB window.
Open the form and it should work.
You can play around with the filters and filterindex to customize it a little.
Look at the other code in the module for ideas on how it works.
Good Luck.




--
Thanx in advance!

jmonty


Jason V said:
I want the user to be able to browse for a file and when chosen, the file
name and path are inserted in an unbound Text box. I have found several
references to the code in the link below but I don't know how to make it work
in my database.

http://www.mvps.org/access/api/api0001.htm
API: Call the standard Windows File Open/Save dialog box

Do I just copy and paste the code into my VBA window? When I do I get an
error, "Only comments may appear after End Sub, End Function, or End
Property".

Thanks
 
S

sadat

Thank you for your step by step description. It really works but the problem
is when ever I try to select a file and press ok a warning message appears.
It says "Run time error: 424, Object Required". Then if I press debug it goes
to the following code:

Private Sub Command21_Click()
MasterTable.Image = TestIt()
End Sub

where mastertable is the name of my table (where I want the file path to be
recorded.

Any one please help.

Thanks and regards,
Sadat
 

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