Loek
Registered User.
- Local time
- Today, 11:52
- Joined
- Feb 6, 2011
- Messages
- 14
I am new in access and I am sorry before. My English not good.
I have main form (f_order) with a subform (f_order_detil) and was linked with order_id. I want print line by line like receipt in the mini market or etc. But, my problem is I can't read the data (field) in a subform using VBA. then I was try the code :
Private Sub cmdPrint_Click()
Dim strSQL As String, strLine1 As String, strLine2 As String
Dim db As DAO.Database, rst As DAO.Recordset
Dim lReturn As Long, lpcWritten As Long, sWrittenData As String
set strSQL = "SELECT*FROM q_rcp" 'q_rcp is my query_order
set db = CurrentDb()
set rst = db.OpenRecordset(strSQL)
strLine1 = rst!order_id 'field in main form
strLine2 = rst!product & rst!price 'field in a subform
sWrittenData = strLine1 & vbCrLf & _
strLine2 & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
it is working properly. But the fields in my subform just one record (not many record like a form on screen). Then I gave criteria :
strSQL = "SELECT * FROM q_rcp WHERE" _
"order_id=" & Forms![f_order_detil]!order_id
I have error clause
any one help me....?
thanks
I have main form (f_order) with a subform (f_order_detil) and was linked with order_id. I want print line by line like receipt in the mini market or etc. But, my problem is I can't read the data (field) in a subform using VBA. then I was try the code :
Private Sub cmdPrint_Click()
Dim strSQL As String, strLine1 As String, strLine2 As String
Dim db As DAO.Database, rst As DAO.Recordset
Dim lReturn As Long, lpcWritten As Long, sWrittenData As String
set strSQL = "SELECT*FROM q_rcp" 'q_rcp is my query_order
set db = CurrentDb()
set rst = db.OpenRecordset(strSQL)
strLine1 = rst!order_id 'field in main form
strLine2 = rst!product & rst!price 'field in a subform
sWrittenData = strLine1 & vbCrLf & _
strLine2 & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
it is working properly. But the fields in my subform just one record (not many record like a form on screen). Then I gave criteria :
strSQL = "SELECT * FROM q_rcp WHERE" _
"order_id=" & Forms![f_order_detil]!order_id
I have error clause
any one help me....?
thanks
Last edited: