Results 1 to 14 of 14
  1. #1
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44

    Exporting only current record

    Hello.
    I have designed a form to perfectly fit the A4 paper, I added 'print the current record' button and it works nicely.
    But I want to be able to export that file, or send it to mail - ONLY THE CURRENT RECORD


    I have tried this macro, but when I click on that button it exports all records. Is there a way to export only the record I'm viewing?


    Also, I know forms are not meant for printing, but report wasn't good enough and I modified this form to fit the A4 paper.

    Click image for larger version. 

Name:	print.JPG 
Views:	26 
Size:	29.5 KB 
ID:	43647

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I would expect you would have to use a form which is either filtered for just that one record or the source is just that one record.

    Try a filter first.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Use the key of the current record. Query pulls the 1 rec.
    docmd.sendto acQuery, "qsMyquery",acFormatPDF, "bob@acme.com"

    or a report:
    docmd.sendto acReport, "rMyReport",acFormatPDF, "bob@acme.com"

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by santon View Post
    But I want to be able to export that file, or send it to mail - ONLY THE CURRENT RECORD
    The procedure (in form's code) is going like this:
    Code:
    '[...]
    DoCmd.OpenReport "MyReport", acViewReport, , "recordID=" & Me.recordID, acHidden
    DoCmd.OutputTo acOutputReport, "MyReport", acFormatPDF, CurrentProject.Path & "\MyReport.pdf"
    DoCmd.Close acReport, "MyReport"
    '[...]

  5. #5
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    I don't have a report, I see in your code names of the report and I don't have it.
    I want to export the current record in my form, to be visually the same. I don't want reports.

    Also filtering is not an option, I want the users only to click the "button" on the current form/record they want to export and send by mail and that's it.
    I need exactly the same output as it appears on the screen/paper

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by santon View Post
    I don't have a report, I see in your code names of the report and I don't have it.
    I want to export the current record in my form, to be visually the same. I don't want reports.

    Also filtering is not an option, I want the users only to click the "button" on the current form/record they want to export and send by mail and that's it.
    I need exactly the same output as it appears on the screen/paper
    YOU set the filter
    YOU run the macro
    YOU unfilter the form

    the user has no idea as what has just happened to make the process work.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You can save your current form as a report (open ir in design view then go to Save Object As and choose report) and change its record source to only include the current record loaded in the form. Now you have a single record report that looks exactly like your form and can be emailed using Docm.SendObject acReport, exported to PDF (Docmd.OutputTo), etc.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I have designed a form to perfectly fit the A4 paper,
    That was your first mistake. Forms usually don't print reliably. You might have it looking OK now, but that can change.
    I don't want reports.
    Then you have your answer in posts 2 and 6.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Micron View Post
    That was your first mistake. Forms usually don't print reliably.
    I know reports are for printing, but considering that I was given this project and I haven't work in Access never, and considering I just started where previous guy left off,
    also time was a issue, this was the best temporary solution for all. I know you are right.




    Ok, I converted form to report, how exactly can I set the record source to the form currently open?
    Also, when I enter new record in my forms, will report be updated automaticaly or I have to convert it again?

    Really sorry for stupid questions, I've just started learning this program.

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Open the report in design view, go to properties, click the builder (the three dots) on the right of the record source property and the source will open in design view. Look for the uniques identifier of the record (some sort of ID) and in the criteria row enter a referenc eto the open form's ID control (will be something like Forms![frmYourForm]![YourID]). Save the record source with a new name if the original was a saved query. Now the report should only have the record loaded in the form. And no, you do npt have to do it everytime.

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Gicu View Post
    Open the report in design view, go to properties, click the builder (the three dots) on the right of the record source property and the source will open in design view. Look for the uniques identifier of the record (some sort of ID) and in the criteria row enter a referenc eto the open form's ID control (will be something like Forms![frmYourForm]![YourID]). Save the record source with a new name if the original was a saved query. Now the report should only have the record loaded in the form. And no, you do npt have to do it everytime.

    Cheers,
    Vlad

    1.
    Click image for larger version. 

Name:	korak 1.JPG 
Views:	15 
Size:	16.9 KB 
ID:	43673

    2.
    Click image for larger version. 

Name:	korak 2.JPG 
Views:	15 
Size:	11.9 KB 
ID:	43674

    3.
    Click image for larger version. 

Name:	KORAK 3.JPG 
Views:	15 
Size:	16.1 KB 
ID:	43675


    I did as you said, when I try to export it, it gives me this to input the number for every control on the field:

    Click image for larger version. 

Name:	output.JPG 
Views:	15 
Size:	24.2 KB 
ID:	43676

    and then exports the file with the values I enter

    Also, I have 2 forms (2 parts of the machine) and they both have the same table as record source, is that a problem?

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You need to select all the (needed) fields from the table, not just the ID. The report should had already have the fields (as the report started as the form), so all you needed was to put the criteria in the ID field.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Gicu View Post
    You need to select all the (needed) fields from the table, not just the ID. The report should had already have the fields (as the report started as the form), so all you needed was to put the criteria in the ID field.

    Cheers,

    I've done it and it works. Thank you so much

  14. #14
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Glad to hear, good luck with your project!

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 08-18-2018, 10:23 AM
  2. Replies: 7
    Last Post: 01-04-2018, 06:35 PM
  3. Replies: 8
    Last Post: 07-23-2017, 02:04 PM
  4. Replies: 3
    Last Post: 02-06-2015, 01:18 PM
  5. Replies: 16
    Last Post: 02-06-2013, 03:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums