this one should just be quick..... (1 Viewer)

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
like my normal quickies!!!!!!that just take oh...forever!

i have a form with a button on it the button prints a report!
the report is based on the table that the form is bound to!
when i click on the print button it prints the report ok well definatly prints the report cos' i bleepin prints the whole tables worth of records all at the same time!:rolleyes: oh no!not suppoz 2 do that!:p never mind

basicaly i want the report only to print ONE record (cos' im going through far to many trees at this rate)
there is a reference number on the form so when i press print i just want it to match the ref number and print that record from the table!
 

Fizzio

Chief Torturer
Local time
Today, 10:14
Joined
Feb 21, 2002
Messages
1,885
Use the criteria argument of the openreport command ie

docmd.openreport "YourReport",acviewnormal,,"[RecordID] = " & Forms!YourForm!RecordID
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
Thanx.... i ment to say that a while ago
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
It cant seem to find my form! i have checked the name over and over again but it just cant find it in a macro or visual basic code! and it is the correct spelling

stDocName = "MethPrescriptionPrint"
DoCmd.OpenReport stDocName, acViewNormal, , "[Ref:] = " & Forms!Methadone_Script!Ref:
 
R

Rich

Guest
The code has to go in the event procedure for the button, not on the property sheet
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
its in the Build event...of the button.
e.g i right click on the button and go to Build event
if thats not correct would i go to properties of the button and the on open event??
 

Fizzio

Chief Torturer
Local time
Today, 10:14
Joined
Feb 21, 2002
Messages
1,885
It should be behind the on_Click event of the button.
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
yup its in the on_click bit and it still said

it cant find the form Methadone_Script in a macro expression or visual basic code!

Methadone Script is the name of the form spelt correctly.
It has a space so in the code i have _ as the space! i have no idea how to fix this! :confused: :(
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
Private Sub Command134_Click()
On Error GoTo Err_Command134_Click
'command134 being print the methadone script button

DoCmd.RunCommand acCmdSaveRecord

' only print the current record
Dim filter
filter = "Ref:= Forms!Methadone_Script!Ref:"
DoCmd.OpenReport "MethPrescriptionPrint", acViewPreview, , filter

NumberofDosesTxT.Value = GetNumberText(Number_of_Doses.Value)

Total_Amount_TxT.Value = GetNumberText(Total_Amount.Value)

DoseInmgtxt.Value = GetNumberText(Dose_mg.Value)

DaysTxT.Value = GetNumberText(Weeks.Value)

Dim stDocName As String
Dim MyForm As Form

'if the Supervised box is clicked the start date of the prescription
'is stored in Text94(the textbox on the form for date lst supervised)
'as the Date Last Supervised

If Supervisedcheck = True Then
Text94 = Start_Date
End If

Exit_Command134_Click:
Exit Sub

Err_Command134_Click:
Msgbox Err.Description
Resume Exit_Command134_Click

End Sub

this code here is coming up with

syntax error(missing operator)in query exprssion'(Ref:=Forms!Methadone_Script!Ref:)'.
 

Tiro Cupidus

Registered User.
Local time
Today, 04:14
Joined
Apr 25, 2002
Messages
263
lynsey2 said:
filter = "Ref:= Forms!Methadone_Script!Ref:"
DoCmd.OpenReport "MethPrescriptionPrint", acViewPreview, , filter
From looking in the help file in access, it seems your filter should be one comma back:

DoCmd.OpenReport "MethPrescriptionPrint", acViewPreview, filter

There is supposed to be a Where clause where you currently have the filter.

Also, it says the filter should be the name of a query in your database... not sure if that'll help. I've never used that 'Ref:=' text :D
 
Last edited:

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
oh thanks! I couldnt find anything in help file!
ill try that!:)

oh Ref: is just a name of my field
 
Last edited:

Fizzio

Chief Torturer
Local time
Today, 10:14
Joined
Feb 21, 2002
Messages
1,885
Lynsey,

The correct syntax is below but it may be having problems with the colon in Ref:. It is never a good idea to use punctuation in field/control names.
filter = "[Ref:] = " & Forms!Methadone_Script!Ref:
DoCmd.OpenReport "MethPrescriptionPrint", acViewPreview, , filter

Im not sure if this will work but it is worth a try
filter = "[Ref:] = " & Forms!Methadone_Script![Ref:] 'Format Forms!FormName!ControlName
DoCmd.OpenReport "MethPrescriptionPrint", acViewPreview, , filter

If no joy, try changing the name of the control to something more like
txtRef and use that in your argument.

Tiro is right on the comma issue but we are trying to use the where argument of the openreport method. Using 'filter' as a variable could make it look confusing;)
 
Last edited:

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
oh dear i have hidden a table now i cant find it oh no! my forms are throwing errors at me cos they cant see it either do you know how to fix this i thought i would get it back easily enough.
 

Tiro Cupidus

Registered User.
Local time
Today, 04:14
Joined
Apr 25, 2002
Messages
263
On the menu: Tools > Options > View Tab, check 'View Hidden Objects'. Then you can go to the table properties and unhide it again.
 

Tiro Cupidus

Registered User.
Local time
Today, 04:14
Joined
Apr 25, 2002
Messages
263
Fizzio said:
Tiro is right on the comma issue but we are trying to use the where argument of the openreport method. Using 'filter' as a variable could make it look confusing;)
Hehe :D
Indeed I was (confused). I didn't know what the string text assigned to 'filter' was, so I assumed it was intended to be the filtername referred to in Access Help.
 

lynsey2

Registered User.
Local time
Today, 10:14
Joined
Jun 18, 2002
Messages
439
oh thank you so so so much i didnt know how to do that! heart failure! didnt think i could fix that! i has worked thank you.:rolleyes:
 

Users who are viewing this thread

Top Bottom