473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access 2007 - VBA to Select External Data Ribbon

Can someone tell me the VBA code to use in my module to select the External Data ribbon? I have a module that runs through some queries and at the end of them I want to export the query to Excel. I would like to show the Ext. Data ribbon to manually (or by code) select "Saved Exports" (I'll need to input a new filename each time). The line of code would be much appreciated. And would it matter if I did that before or after Setting Warning back to true?

Thanks much!
Cele
Nov 21 '08 #1
21 7278
Megalog
378 Expert 256MB
I'm not entirely sure what you're asking for here.. Do you wish to simply pull up the Saved Exports menu programmatically?

Expand|Select|Wrap|Line Numbers
  1. Application.RunCommand acCmdSavedExports
If you need to actually load a new ribbon, or move to a different grouping within your existing ribbon, let me know.
Nov 24 '08 #2
That is perfect! Exactly what I wanted to do!! Thanks a bunch!
Cele
Nov 25 '08 #3
Megalog
378 Expert 256MB
An easy fix after all =)

Welcome to Bytes!
Nov 25 '08 #4
Zach85
11
Is there a way to just have a saved export command run at the click of a button, or can I only just have it open the saved exports application and I still have to click on the export command I want it to?
Feb 12 '09 #5
Megalog
378 Expert 256MB
If you know the name of the saved import/export, and dont want any prompting whatsoever, you can use the following:

Expand|Select|Wrap|Line Numbers
  1. docmd.RunSavedImportExport "YourSavedImportorExportName"
Feb 12 '09 #6
Zach85
11
Thanks

Another question... since I'll be giving this to the guys I'm doing this for, is there a way to not have the longer filepath, but rather just look for, or export to, a file in the same folder? I tried to go (from my html background) with just putting in the file name, but that doesn't work, it just thinks to look for C:\filename.mdb

Thanks again so much for your help!
Feb 12 '09 #7
Megalog
378 Expert 256MB
Just to clarify what you're asking, you want your export to show up in the same folder that the database itself is currently in?

I believe if you use a saved export, you're locking in all the variables.. filename, path, etc. If you need to change this to add in some path detection, then you'll want to be using the docmd.OutputTo command, and then adding in the correct criteria behind that.
Feb 12 '09 #8
Zach85
11
I'll try to explain my problem:

Let's say I have the Access 2007 database in the following folder:

C:\database\

Right now, when I went through the export wizard to save the export, it asked me where to export to and I put in:

C:\database\file.mdb

Now if I were to take this database and put it on my external hard drive and take it to another computer and tried to run the saved export command, it'll give me an error, something like:

"C:\database\file.mdb is not a valid filepath"

I want it to export to a file in the SAME folder as the 2007 database file. But, my problem is that the filepath in the saved export is always static. I tried just typing the file name, assuming it would look first in the same folder if I did that instead of following a path. that didn't worked, it just looked for C:\file.mdb. Is there a way, like in html where you just type in "page.html" into the "a href" command instead of having to type the whole url in?

sorry if that does not made sense, but I think that's the best I can do. Thanks
Feb 12 '09 #9
Zach85
11
I got it to work by just messing around with it.

After the wizard to save the export, I went into the Saved export application and changed the file path to "./filename.mdb" which worked.

Thank you so much for your help on this, and the attempted help of the last problem I had. I sincerely appreciate it!
Feb 12 '09 #10
Zach85
11
it only works when you first do that. Then when you close the 2007 database and open it back up and try exporting it with that ".\filename.mdb" it just looks in the my document folder for some reason. I'll just use the long filepath then, it doesn't seem to be any other way.

Thanks again.
Feb 12 '09 #11
Megalog
378 Expert 256MB
Here's one way to do it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExport_Click()
  2.  
  3. Dim strDB As String
  4. Dim lngPath As Long
  5. Dim lngRev As Long
  6. Dim strLeft As String
  7.  
  8. strDB = Application.CurrentDb.Name
  9. lngPath = Len(strDB)
  10. lngRev = InStrRev(strDB, "\")
  11. strLeft = Left(strDB, lngPath - (lngPath - lngRev))
  12.  
  13. DoCmd.OutputTo acOutputTable, "listview", acFormatTXT, strLeft & "YourExport.txt"
  14.  
  15. End Sub
You'll need to change the OutputTo variables to fit your situation (I'm exporting a table to a text file in my example), but it will place it wherever your database resides.
Feb 12 '09 #12
Zach85
11
I can't use the acFormat because there's no way to format it to mdb. I need to export it to filename.mdb, can't export it to txt,xls or any of the other acFormat extenstions that are supported.
Feb 12 '09 #13
Megalog
378 Expert 256MB
? What are you trying to do? Save a copy of the current 2007 database to the same folder as 2003 format? Please explain fully what it is you're trying to export.
Feb 12 '09 #14
Zach85
11
ok, here goes...

I started this database of contact people for my internship supervisor. I have the file saved as "contact list.accdb" which is the access 2007 extension. I wanted to import that into a marketing program I found, Email Marketing Program. It doesn't support the accdb extension (yet) and so I want to export the accdb format to the mdb format (Access 2003) in order to import it to EMP.

I tried using Save as, but that saves the WHOLE accdb program, when I just want to export the contact list (which is one of like 5 or 6 components of the accdb program). it will not open properly in the mdb extension because some of the stuff I'm using in the 2007 is new in 2007 and will not open in 2003.

Does that make better sense? Sorry if I wasn't clear previously.

If I have to, I could try exporting to txt comma delimited, but I'd much rather just keep it simple with two separate access files, one in 2003 and one in 2007. Thanks again.

I have to go now so I won't be able to respond for most of the day. I'll let you know how things go later tonight or tomorrow when I get back to working on my internship stuff. Thanks!
Feb 12 '09 #15
Megalog
378 Expert 256MB
So you basically want an .mdb, that holds only the tables with your contact information.. If you're using multi-value fields, or anything else specific to 2007, then I would suggest you either export to a comma delimited text file, only exporting the fields you need. Or, create an mdb, and then have your 2007 db run an update query on the mdb whenever your contact data gets updated. This would require you to link tables from the mdb to the accdb, and then dynamically relink when the files move around. Is there an advantage to using an mdb file, instead of a cst file, with this EMP program?
Feb 13 '09 #16
Zach85
11
Good point. I'm putting some contacts into the database right now from this one league. When I'm done this league, I'll see about exporting to a csv prior to starting on another league. Thanks!

Sorry for the delay in response, I had a rough weekend. Thanks again!
Feb 16 '09 #17
Zach85
11
Ok. I got it to work how you programmed it. It looks like a table in a text file, and I got confused. But then I realized that the acOutput is to a Table. Is there a way to have it export it as csv? This way it'll be able to read in the EMP? I don't think it will read as a table, but I won't be able to figure that out at the moment since I am in the computer lab working on this. I will be leaving her shortly to go back to my room, where I can test it to see how it turns out. If I can get it to do csv or some other delimited (i.e. tab) that would be great and much easier on my supervisors.
Feb 16 '09 #18
Zach85
11
Ok, I thought about it and I don't think the output way will work unless there is a specific way to export it to CSV.

Then, I thought, is there a way to save as, and then do the same way you did it with the output, by setting the strings and then having it like leftStr & "contacts.mdb" or whatever?

I then found acCmdSaveAs in the command library, but don't know how to use it and tried googling it but to no success. Think you could help me? This might make it work easier and this way I could just save it or export it as a mdb for better luck. Thanks in advance
Feb 17 '09 #19
Megalog
378 Expert 256MB
Sorry I was out monday. The command you'll want for this is DoCmd.TransferText. Do a manual export, and save any settings you want to a new Export Specification. Then, you can call upon that specification in your TransferText command as well, for example:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText  acExportDelim,"SavedSpecificationName(Optional)","YourTableorQueryName","C:\Data\Exported Contacts.csv"
Now the filename portion can be built beforehand, using a bit of that code I posted earlier to build your db location string. Then you can add on a filename, and timestamp it as well. Or.. just overwrite whatever is existing in that current location if you want a static filename. Hit the help file on TransferText, and if you need any suggestions just ask away.

-Mega
Feb 17 '09 #20
Zach85
11
You, my friend, are a genius! It worked with the following:

Dim strDB As String
Dim lngPath As Long
Dim lngRev As Long
Dim strLeft As String

strDB = Application.CurrentDb.Name
lngPath = Len(strDB)
lngRev = InStrRev(strDB, "\")
strLeft = Left(strDB, lngPath - (lngPath - lngRev))

DoCmd.TransferText acExportDelim, , "Contacts", strLeft & "contacts.csv"

I didn't use the specification name, only because I don't know what that is. But like you said, it is optional and this works without it!

THANK YOU THANK YOU THANK YOU SOOOO MUCH! This certainly will reduce the headaches for my supervisors when I am done my internship and give them the program to use.

Thanks a lot, I really do appreciate it. I hope I wasn't bothersome haha, but this meant a whole lot to get something like this done. I really should learn VB now, since I plan to use access and excel a lot in the future. VB is very helpful!
Feb 17 '09 #21
Megalog
378 Expert 256MB
Good to see it all come together and work, eh? Glad you got your problem fixed.. and yes, vb is great.. you'll definitely find many uses for it in Excel as well as Access.

BTW, in the future, please put code tags around any vb you post. It's the '#' button in the posting editor.
Feb 17 '09 #22

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

Similar topics

37
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why...
27
by: Wayne | last post by:
I've been clicking around Access 2007 Beta 2 and can't see the custom menu bar designer. Is it in the beta? Maybe I'm blind. The question that comes to mind is: Will custom menu bars be the same...
7
by: denuk2003 | last post by:
Hi Everybody I have a 2003 application that I am trying to run under 2007, The code seems to work OK but the Ribbon is a big problem. It just takes up too much space away from the application. ...
6
by: plasyncoed | last post by:
Hello all We have an Access 95 database which holds a lot of our customer data. We are running the database in Access 2007 and in the main it's fine. However the time has come to move on and...
2
by: Wayne | last post by:
I've been having a click around Access 2007 this afternoon and have discovered some things that range from annoying to alarming. My Access 2003 menu bars, which I, like many others, use...
6
by: ARC | last post by:
Ok, so I'm looking at Access 2007, and I have imported my existing Access 97 application. I'm feeling a bit overwelmed in what to do here. In my original 97 application, I had one form: Mainmenu,...
6
by: tony.abbitt | last post by:
I have recently installed Office 2007 (SP1) retaining the previous installation of Office 2003. I have converted an Access 2003 database to Access 2007. The database contains the VBA code...
4
by: Bob | last post by:
Hi, Can it's possible to use a customized QAT in Access 2007 with a Ribbon using "USysRibbons" ? because in Access options i can't select 2 ribbon name. Thank's
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.