473,473 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Open Excel File from Access Form using Wildcards

3 New Member
Hello,

I'm somewhat new to Access and I'm trying to open an Excel file from an Acess form command button. The only problem is the Excel filename includes a date and the date changes on a weekly basis. Is there a code that I can use use that supports wildcards?

Thank you in advance!
Oct 28 '09 #1
6 4547
ChipR
1,287 Recognized Expert Top Contributor
As far as I know, you do have to name one specific file to open. You can get the filename easily with the Dir command if you can determine the location of the file.
Oct 28 '09 #2
brunpam
3 New Member
Thanks for the quick response. I'm sorry - but I'm not familiar with the DIR command. I'm new to this. Can you give me an example using DIR in a code.
Oct 28 '09 #3
Delerna
1,134 Recognized Expert Top Contributor
click on the blue underlined word Dir in chipr's post.
It is a link to all the info you need
Oct 28 '09 #4
ADezii
8,834 Recognized Expert Expert
@brunpam
You never stated whether or not the location of your Excel File was static or dynamic. In light of this, I wrote comprehensive code that will:
  1. Open the Standard Office File Dialog Window.
  2. This Dialog will only display Excel (*.xls) Files and no other Files.
  3. Once you Navigate to, then select a File, it will then Open it in Excel.
  4. Do not forget to:
    1. Set a Reference to the Microsoft Office XX.X Object Library.
    2. Change the value of the Constant pointing to the Path to Excel.exe, if necessary.
  5. If you decide to use this approach, and need further help, we re here.
Expand|Select|Wrap|Line Numbers
  1. 'First, set a Reference to the Microsoft Office XX.X Object Library
  2.  
  3. Dim strButtonCaption As String
  4. Dim strDialogTitle As String
  5. Dim varFileSelected As Variant
  6. Dim varRetVal As Variant
  7. Const conEXCEL_PATH = "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE"
  8.  
  9. 'Define your own Captions if necessary
  10. strButtonCaption = "&Open"
  11. strDialogTitle = "Select Excel File to Open"
  12.  
  13. With Application.FileDialog(msoFileDialogOpen)
  14.   With .Filters
  15.     .Clear
  16.     .Add "Excel Files", "*.xls"                 'Allow Excel Files only
  17.   End With
  18.   'The Show Method returns True if 1 or more files are selected
  19.     .AllowMultiSelect = False                   'Critical Line
  20.     .ButtonName = strButtonCaption
  21.     .InitialFileName = vbNullString
  22.     .InitialView = msoFileDialogViewDetails     'Detailed View
  23.       .Title = strDialogTitle
  24.   If .Show Then     'File selected
  25.      varFileSelected = .SelectedItems(1)        'Can only be 1 File selected
  26.      'Open the Excel File
  27.      varRetVal = Shell(conEXCEL_PATH & " " & Chr(34) & varFileSelected & Chr(34), vbMaximizedFocus)
  28.   End If
  29. End With
Oct 28 '09 #5
maxamis4
295 Recognized Expert Contributor
If you are new to Access you want simple. The best way is to go to the button properties and under On Click paste this code. All you will have to do is change the path, the directory where the excel sheet is located.

Additionally in the code page of Access you will need to go to tools >>Reference
Select the following object library. This step you will have to do for any of the code examples provided. "Microsoft Excel xx.0 Library" xx version of excel, pick the latest.

Expand|Select|Wrap|Line Numbers
  1. use xlApp.Workboks.Open
  2.  
  3. Dim xlApp As Excel.Application
  4. Dim xlWB1 As Excel.Workbook
  5.  
  6.    Set xlApp = New Excel.Application
  7.  
  8.    xlApp.Visible = True
  9.  
  10.    Set xlWB1 = xlApp.Workbooks.Open("e:\paige\vb program\delinquent.xls")
  11.  
  12.    xlWB1.Close
  13.  
  14. Set xlWB1 = Nothing
  15.  
  16.    xlApp.Quit
  17.  
  18. Set xlApp = Nothing
  19.  
  20.  
Oct 28 '09 #6
brunpam
3 New Member
Thank you all for your quick response!
Oct 29 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: VbUser25 | last post by:
hi.. i have a form i accept some user inputs in the form. there is a link on the form from where i open the excel file in the same browser (not in a new page...simply using a href. i am also...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
2
jaccess
by: jaccess | last post by:
I was wondering if there is a simple way to open a specific folder from an access form button. I have a form that a user can enter a date range and either view or print reports based on the date...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
1
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created...
8
by: shenkel55 | last post by:
I'm using Access and Excel 2003. Using either the import wizard or code, I have the same problem. This problem only happens with Excel files automatically generated by Corp IT. If I try to do an...
22
by: robertgregson | last post by:
Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client. The service uses...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.