473,555 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I use DoCmd.OutputTo to export the current record only?

16 New Member
Hello all,

I would like to create a command button on a form that will allow the user to export the current record to .xls.

The following exports the entire table. Is there a way to export the current record being viewed only?

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputForm, "frmInputView", acFormatXLS, "filename.xls", False
Many thanks,
Tim
Mar 4 '11 #1
2 12348
ADezii
8,834 Recognized Expert Expert
Just subscribing for now...will return with an idea later.
Mar 5 '11 #2
ADezii
8,834 Recognized Expert Expert
  1. Declare Variables to hold the Original and Modified Record Sources
    Expand|Select|Wrap|Line Numbers
    1. Dim strOriginalRecordSource As String
    2. Dim strNewRecordSource As String
  2. Retrieve the Original Record Source of the Form
    Expand|Select|Wrap|Line Numbers
    1. strOriginalRecordSource = Me.RecordSource
  3. Create a New Record Source based on the Primary Key displayed on the Form
    Expand|Select|Wrap|Line Numbers
    1. strNewRecordSource = "SELECT * FROM tblEmployees WHERE [ID] = " & Me![ID]
  4. Apply the Filtered Record Source to the Form
    Expand|Select|Wrap|Line Numbers
    1. Me.RecordSource = strNewRecordSource
  5. Output the Single, Form Record
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OutputTo acOutputForm, "frmInputView", acFormatXLS, "filename.xls", False
  6. Restore the Original Record Source
    Expand|Select|Wrap|Line Numbers
    1. Me.RecordSource = strOriginalRecordSource
  7. Complete Code with Comments stripped:
    Expand|Select|Wrap|Line Numbers
    1. Dim strOriginalRecordSource As String
    2. Dim strNewRecordSource As String
    3.  
    4. strOriginalRecordSource = Me.RecordSource
    5. strNewRecordSource = "SELECT * FROM tblEmployees WHERE [ID] = " & Me![ID]
    6.  
    7. Me.RecordSource = strNewRecordSource
    8.  
    9. DoCmd.OutputTo acOutputForm, "frmInputView", acFormatXLS, "filename.xls", False
    10.  
    11. Me.RecordSource = strOriginalRecordSource
Mar 5 '11 #3

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

Similar topics

1
8793
by: Tim Graichen | last post by:
I currently populate a form based on a query. 1)How do I create a report that displays only the current record's fields and not all records in the table? Thanks Tim G
4
4135
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I want all of the controls in whatever is the CURRENT record to have it's data bolded on the screen. (Question #1: Is there a SIMPLE way to refer to...
2
7345
by: OSMeier | last post by:
Hi Everyone, I am hoping you can help me. I am using MS Access 2000 for this. Here is the scenario: I have two tables: tblMain -------- ID (Primary Key)
0
1965
by: user_5701 | last post by:
I have an Access 97 database front end (with some lookup tables there too) which also has a MS SQL Server 2000 back end, where all the rest of the larger tables are. I recently had some problems with people being able to access things, getting ODBC errors when trying to open tickets. I checked the file DSN advanced configuration and changed...
1
3308
by: David | last post by:
Hi, I have a continuous form. For each record I have a field 'HeldDate' (Text Field from a table) Against each record I have a button which sets the visibility of this text box to 'True' and does various other actions. Is it possible to display the text box just for the current record, rather than it displaying for all following records...
0
1281
by: jennywhatley | last post by:
Hello I am using the following code to try to get a report to show a single record by clicking a command button in a sub form (perhaps it doesnt work because its a sub form not a form?) The mainform holds the primary key and subform displays the data. My other complication is that the primary key is a combination of 2 fields, however,...
1
5309
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. Next the user can go into a Form which basically a dynamic query with a friendly interface that eventually outputs a table that is stored in the DB as...
0
1441
by: Andy | last post by:
Hi ! I have a form that displays several records. The record contains a bound object frame. Onclick I execute some simple code to change teh object's appearance then I requery. The trouble is that it requeries the entire record set so my object refreshes ( good ) but I have to wait for the requery to work it's way thru the entire record...
2
2139
easydoesit
by: easydoesit | last post by:
Hello all, I am looking for a way to be able to enter data into fields on a form, then be able to e-mail a report that shows only that record. This is what I have thus far: At the end of my Form, I have a Command Button. Right now the Command Button has an On Click... to basically E-mail a Report. Here is my Visual Basic code for it:
2
3749
by: jmartmem | last post by:
Greetings, I have several Access 2007 reports that I regularly export to individual PDF flat files on a web server. I've successfuly created a module sub to export the reports using the DoCmd.OutputTo Macro action, but I can't seem to figure out how to run the macro automatically. I can succesfully run the macro below manually (without the...
0
7547
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5171
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3596
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.