 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 26th, 2011, 07:17 AM
|
|
Registered User
|
|
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Transfer File - Need a "like" command for file Name
Hi All,
I need to import a file that has trailing character that is not needed. For example, all states have the following file name Apples_STATE_Oranges_XX_YY_DD_FF where XX_YY_DD_FF change with each state where as APPLES_STATE_ORANGES stays constant however with state being dynamic.
Code:
Location1 = Location & "Oranges.xls"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "cOranges", Location1, True
The problem is access can't find "oranges.xls" because in the destination folder its oranges_xx_yy_zz_dd.xls"
Any help would be greatly appreciated 
|
|

May 26th, 2011, 10:56 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Are there other files in the folder?
You could use the Dir Function to grab the filename of each file in the folder, then compare Left$(filename, 7) with "Oranges" to see if it matches.
|
|

May 27th, 2011, 08:43 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Hi there..
The dir command is a nice solution, but you can also do something like DIR("oranges*), to get all the files that match the start with oranges...
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

May 27th, 2011, 01:24 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
|
|
The DIR() does use wildcards similar to how Jet/ACE (Access) SQL does with t he LIKE.
If you want all XLS files starting with orange then use:
Dir("\\path\folder\orange*.xls")
Check the help to see how to use DIR() to find all the files in a folder that match your search..
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
|
|

May 28th, 2011, 07:24 PM
|
|
Registered User
|
|
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by JP
Are there other files in the folder?
You could use the Dir Function to grab the filename of each file in the folder, then compare Left$(filename, 7) with "Oranges" to see if it matches.
|
Thanks! I have multiple files in the folder ....for example
xx_yy_STATE_Oranges_Blah
xx_yy_STATE_apples_Blah
xx_yy_STATE_pears_BLAH
I'm using a form to so if I showed the file path to say "xx_yy_me.state.value &"_" Dir(oranges*) ...would that work?
Thanks for your help!
|
|

May 29th, 2011, 12:09 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
|
|
<<I'm using a form to so if I showed the file path to say "xx_yy_me.state.value &"_" Dir(oranges*) ...would that work?>>
No.
Did you check the help for the DIR() function?
You will need or the full path as the parameter for the DIR().
On your form are you wanting to list all the files in a folder that match your search string? If yes the you will have to use some VBA code to read all the file names and popular some type of control. You could use a List box, Combo box, or tree view control.
This may help:
http://www.everythingaccess.com/tuto...es-recursively
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
Last edited by HiTechCoach; June 7th, 2011 at 06:58 PM..
|
|

June 7th, 2011, 01:18 PM
|
|
Registered User
|
|
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
File - Need a "like" Command - Worked!
Thank you all for your help!
Code:
location = f1
location = f1 & me.state.value
Location1 = Dir(Location & "oranges*.xls")
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "cOranges", Location1, True
Thank you! Thank you! Thank you! 
Last edited by rachmul18; June 7th, 2011 at 01:19 PM..
Reason: Code not showing correctly
|
|

June 7th, 2011, 06:59 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
|
|
You're welcome.
Glad we could assist.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015
|
|
 |