Hey all, need some input on coding for a form. Years ago I had developed some stuff in Access for handling some different tasks at work. Well, that stuff doesn't work quite as well anymore. Hurray for non backwards compatibility. I've decided to dive into redeveloping things, start fresh as it were. One of the tasks that my database handles is processing incoming product returns. I've got a form that contains customer info and basic shipping info and such. In the details portion of the form I have a subform where the actual products are entered in for the product returns. Once information is entered in, for the old system I'd click a button and it would load a report that displayed this information. I'm trying to recreate this now in Access 2010. Pretty sure I developed all this originally with Office XP. Yeah, old stuff. Anyway, I'm finding with Access 2010 that I can embed a macro as the action on clicking the button on my form. Seems to be a nifty, simpler version of just straight coding. The issue I have is that when I click on the button to print, whether it just prints or I get the print preview of the report, I want it to only pull the info from that current record including the products associated just with that current record. And as such currently it'll list products but it repeats all items, not just those for the current record. Below is the coding that I had for the original version of my database from a decade plus ago:
Private Sub cmdPrintRecord_Click()
On Error GoTo Err_Handler
DoCmd.RunCommand acCmdSaveRecord
Dim strReportName As String
Dim strCriteria As String
strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error# " & Err.Number & "" & Err.Description
End If
Resume Exit_This_Sub
End Sub
The field [Return Number] was the primary key field for the main return table and is what I used as the foreign key for the table containing the list of products returned for that particular entry. This coding allowed for clicking the button and bringing up a print preview of the report that would display this information. Can someone do one of a couple things. Either give me some suggestions on what I should be putting in for criteria in the embedded macro for this type of thing or otherwise help me to better understand how to modify this code so that instead of previewing the report, it just straight tells the computer to send that report straight to the printer. Both options would be nice as initially I'd like to see the preview to make sure formatting is good and all but eventually set up the database to where it just prints it.
Along with that I'd love to see input on how I could also possibly go with a third option of "printing" the report straight to a PDF file. Holler back if you have any questions for me or need any further info on this project. It's been years since I dove head first into Access. Been taking some doing to learn where things are and what some of the settings do again, especially with changes in version of the program over the years. And I haven't done much coding in a while but fire away. Gives me a good crash course in refreshing my memory on programming. Thanks in advance!