Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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
 
Old May 26th, 2011, 07:17 AM
Registered User
 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old May 26th, 2011, 10:56 AM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
__________________
Regards,
JP
JP SoftTech
 
Old May 27th, 2011, 08:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
================================================== =========
 
Old May 27th, 2011, 01:24 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

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
 
Old May 28th, 2011, 07:24 PM
Registered User
 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by JP View Post
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!
 
Old May 29th, 2011, 12:09 AM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

<<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..
 
Old June 7th, 2011, 01:18 PM
Registered User
 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old June 7th, 2011, 06:59 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

You're welcome.

Glad we could assist.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015





Similar Threads
Thread Thread Starter Forum Replies Last Post
"No rule to process file" superherogeek BOOK: Beginning iPad Application Development 0 July 13th, 2010 01:06 PM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Reading a files general property of "Type of file" GregSivers Visual Basic 2008 Essentials 7 June 3rd, 2009 09:38 AM
Chapter 2 "An attempt to attach an auto-named database for file.." Gredkins BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 4 May 28th, 2009 11:55 PM
Message received by "FILE" adapter is suspended skindika Biztalk 0 February 2nd, 2009 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.