K
Karen
I'm trying to write a bit of code for a button and need a little help
(maybe lots of help).
I have two tables, one is called Reagents and has fields fldcode and
fldprodtype. The second is Ingredients and it has the fields fldcode
and fldrm#. There can be more than one occurance of a code in
fldcode. So I can have a list of the rm#'s that go into the Reagent
named in fldcode.
I want to be able to click a button and have a prep sheet print out
for the code and then have a prepsheet print for any of that code's
rm#'s that are also parents of more rm#'s. for example
Table Reagents: Fldcode -> 4455
Table Ingredients: Fldcode -> 4455 Fldrm# -> 1234
Fldcode -> 4455 Fldrm# -> 5678
Table Ingredients: Fldcode -> 5678 Fldrm# -> 7890
Fldcode -> 5678 Fldrm# -> 8765
I would want a prep sheet for the 4455 and then one for the 5678 since
it has ingredients.
I have the following code now. I've been working on this and now I
don't know how to get to the next step. this does what I expect it to
do. I've written a comment where I think I should be looking for the
rm# as a parent. I'm just not sure how to get there.
********************
Private Sub printprep_Click()
On Error GoTo Err_printprep_Click
Dim dbinfo As Database
Dim rstprep As Recordset
Dim rstrgt As Recordset
Dim rstINGR As Recordset
Dim stDocName As String
Dim sSql As String
If Me!fldprodtype = "Tablet" Then
Set dbinfo = CurrentDb()
Set rstINGR = dbinfpenRecordset("tblingredients")
sSql = "[fldcode] = " & "'" & Me![entercode] & "'"
rstINGR.FindFirst sSql
Do While Not rstINGR.EOF
If rstINGR.NoMatch Then
MsgBox "not found", vbExclamation, "Not Found" 'no ingredients
for this code
rstINGR.close
'*** clear the form and put the cursor back in [entercode]
Exit Do 'while not eof
End If 'nomatch to [entercode]
' if found...
'somewhere in here I need to check to see if the fldrm# is also in the
fldcode somewhere and then print a prepsheet for it.
rstINGR.FindNext sSql
Loop 'do while not eof
End If 'prodtype = tablet
'check to see if this is a pre-mix or bulk powder and print the
appropriate prep sheet
If Me!fldprodtype = "Pre-Mix" Or Me!fldprodtype = "Bulk Powder"
Then
strdocname = "rpt premix prep"
Else
stDocName = "rptprep"
End If 'if prodtype premix or bulk powder
DoCmd.OpenReport stDocName, acNormal
Exit_printprep_Click:
Exit Sub
Err_printprep_Click:
MsgBox Err.Description
Resume Exit_printprep_Click
End Sub
**************************
Thanks for any help!
Karen
(maybe lots of help).
I have two tables, one is called Reagents and has fields fldcode and
fldprodtype. The second is Ingredients and it has the fields fldcode
and fldrm#. There can be more than one occurance of a code in
fldcode. So I can have a list of the rm#'s that go into the Reagent
named in fldcode.
I want to be able to click a button and have a prep sheet print out
for the code and then have a prepsheet print for any of that code's
rm#'s that are also parents of more rm#'s. for example
Table Reagents: Fldcode -> 4455
Table Ingredients: Fldcode -> 4455 Fldrm# -> 1234
Fldcode -> 4455 Fldrm# -> 5678
Table Ingredients: Fldcode -> 5678 Fldrm# -> 7890
Fldcode -> 5678 Fldrm# -> 8765
I would want a prep sheet for the 4455 and then one for the 5678 since
it has ingredients.
I have the following code now. I've been working on this and now I
don't know how to get to the next step. this does what I expect it to
do. I've written a comment where I think I should be looking for the
rm# as a parent. I'm just not sure how to get there.
********************
Private Sub printprep_Click()
On Error GoTo Err_printprep_Click
Dim dbinfo As Database
Dim rstprep As Recordset
Dim rstrgt As Recordset
Dim rstINGR As Recordset
Dim stDocName As String
Dim sSql As String
If Me!fldprodtype = "Tablet" Then
Set dbinfo = CurrentDb()
Set rstINGR = dbinfpenRecordset("tblingredients")
sSql = "[fldcode] = " & "'" & Me![entercode] & "'"
rstINGR.FindFirst sSql
Do While Not rstINGR.EOF
If rstINGR.NoMatch Then
MsgBox "not found", vbExclamation, "Not Found" 'no ingredients
for this code
rstINGR.close
'*** clear the form and put the cursor back in [entercode]
Exit Do 'while not eof
End If 'nomatch to [entercode]
' if found...
'somewhere in here I need to check to see if the fldrm# is also in the
fldcode somewhere and then print a prepsheet for it.
rstINGR.FindNext sSql
Loop 'do while not eof
End If 'prodtype = tablet
'check to see if this is a pre-mix or bulk powder and print the
appropriate prep sheet
If Me!fldprodtype = "Pre-Mix" Or Me!fldprodtype = "Bulk Powder"
Then
strdocname = "rpt premix prep"
Else
stDocName = "rptprep"
End If 'if prodtype premix or bulk powder
DoCmd.OpenReport stDocName, acNormal
Exit_printprep_Click:
Exit Sub
Err_printprep_Click:
MsgBox Err.Description
Resume Exit_printprep_Click
End Sub
**************************
Thanks for any help!
Karen