Report from query based on ID

In Nomine Noctis

New member
Local time
Today, 03:22
Joined
Aug 16, 2013
Messages
9
guys, been searching across google for a answer but found nothing of course...(am n00b in VBA BTW)

the thing is,

there is a query and report "01 qry Main" and from the main FORM I like to print out into txt file actual record, my code is:

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click

Dim stDocName As String


stDocName = "01 qry Main"

DoCmd.OutputTo acOutputReport, "01 qry Main", acFormatTXT, "D:\10 Dbase\CTQ stuff\saveReportFormat.txt", False

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click

End Sub
there should be an option "ID = " & Me.ID.Value or something like this to print out only actual record

Ill be really appreciated for any help with this,
thanks
david
 
wow, job done here, got it

Dim strWhere As String

stDocName = "01 qry Main"
DoCmd.OpenReport "01 qry Main", acViewPreview, , "ID = " & Me.ID.Value
DoCmd.OutputTo acOutputReport, stDocName, acFormatTXT, "D:\10 Dbase\CTQ stuff\saveReportFormat.txt", False

but guys, another question, if I like to name that TXT file as some numerical string, for example "Measurement 0000001.txt" where that number is variable based on count of measurements (based on ID of record lets say)
any ideas?
 
do you mean something like:
Code:
DoCmd.OutputTo acOutputReport, stDocName, acFormatTXT, "D:\10 Dbase\CTQ stuff\saveReportFormat " & format(Me.ID.Value, "00000000") &".txt", False

if you want the count of the query.... lookup dcount function, which you can then use like above example
 
great buddy !!! working well
how it will be if we will add another variable value from record, lets say "PN" or to add now()

file should have name "00000001 CTQ measurement - 202506 (as a PN)_11.10.2013_11:15.txt"

thanks in advance
david
 
Well if you are adding date/time into the string you do so in ISO Format, i.e. 20131011 aka yyyymmdd

You can add as many things as you like as long as you keep the order and keep inserting & at the right place
String & String & Format(Variable) & Format(OtherVariable) & string & String & ".txt"

Also Just a strong advice, Command24 is a beautifull default name, but doesnt mean anything.... The fact that you are using default names for buttons leads to the assumption you are using default names all over the place.
I strongly advice you to not stick to these default names but to give things proper names, like in this case cmdExportReport or something along those lines. That way you can keep making sence of things more easily.
 
2 namliam: thanks buddy for your advice
- dbase is still in construction so thats why I am still using "Command24", thats will be last job for me before going live

I´ve tried to use that PN value as a variable (same format as ID? " & Format(Me.ID.Value, "00000000") & ") as " & Format(Me.PN.Value) & " but it does not working :(
- date and time working fine through " & _ Format(Now(), "dd.mm.yyyy hh.nn.ss") & "
- as I said before, I am n00b in VBA coding...
 
I somehow missed your reply earlier... :(
I hope you were able to work it out otherwize... post back here
 

Users who are viewing this thread

Back
Top Bottom