Print current record as report from form

Rupa

Registered User.
Local time
Today, 19:00
Joined
Nov 14, 2008
Messages
22
Hey all

I am trying to print a record that I have just inserted on my form. My code:

Code:
[SIZE=3][FONT=Times New Roman]Private Sub PrintTempSlip_Click()[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]On Error GoTo Err_PrintTempSlip_Click[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]If (IsNull(StNo.Value) = True) And (IsNull(Forename.Value) = True) And (IsNull(Surname.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Number, Forename and Surname")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(Forename.Value) = True) And (IsNull(Surname.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Forename and Surname")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(StNo.Value) = True) And (IsNull(Forename.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Number and Forename")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(StNo.Value) = True) And (IsNull(Surname.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Number and Surname")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(StNo.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Number")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(Forename.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Forename")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]ElseIf (IsNull(Surname.Value) = True) Then[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please enter your Surname")[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Else[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]DoCmd.RunCommand acCmdSaveRecord[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]Dim stDocName As String[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]stDocName = "Temporary Slip"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]DoCmd.OpenReport stDocName, acNormal[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]MsgBox ("Please collect your temporary slip from a member of staff")[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]DoCmd.GoToRecord , , acNewRec[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]End If[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Exit_PrintTempSlip_Click:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Exit Sub[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3] [/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]Err_PrintTempSlip_Click:[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    MsgBox Err.Description[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    Resume Exit_PrintTempSlip_Click[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]    [/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]

It prints all the records in the table when I would like to print the record I have just inserted.

Any pointers will be highly appreciated.

Many thanks,

Rupa
 
Thanks PBaldy

I tried that before as well but it prints a blank one. Any ideas?

Many thanks,

Rupa
 
I use it all the time, so I know it works. Post the code you tried and the relevant data type(s).
 
DoCmd.OpenReport stDocName, acNormal, , "StNo = '" & Me.StNo & "'"

They are both called StNo

Thanks,

Rupa
 
I see no reason that wouldn't work, presuming StNo is a text data type. Can you post the db?
 
I worked it out!! The values on the report were coming from the table and not the form. It works perfectly now.

Thank you for your help anyway :-) Much appreciated.

Rupa
 

Users who are viewing this thread

Back
Top Bottom