S
Scott A
I trying to do something that I think requires a value to
be passed from one form to another - I tried setting this
up using the link criteria - but the form I'm launching
isn't bound to any data... I'm working on passing the
parameter using OpenArgs, but am not having much success
as of yet.
Here's a little more detail:
I'm essentially trying to set up a transaction form - not
with customers and products, but it's very similar. The
table I need to populate with this form is just like a
customer order table.
So - I have a link from the 'customer' form to
this 'customer orders' form. What I'm trying to do is
show a list of 'products' that the customer can order.
I'm using a list box to show all products on the page.
The list box uses a SQL statement as a row source,
displaying three fields (as columns) from the products
table.
Problem: I need to show as selected, any 'products' that
have already been purchased, and am trying to do so by
querying the database and finding any matches in the
customer order table. I'm thinking that this is not
working because the transaction form that contains the
list box isn't bound to any data - and am trying to pass
the key field using the button that launches the form.
Here's the code:
=========================================================
'Customer' form OnClick Event (customer = SOP)
I intend this code to launch the orders form and pass the
SOPID...
=========================================================
Private Sub cmdDistributionForm_Click()
On Error GoTo Err_cmdDistributionForm_Click
Dim stDocName As String
stDocName = "frmDistribution"
DoCmd.OpenForm stDocName, , , , , acDialog, Me!SOPID
Exit_cmdDistributionForm_Click:
Exit Sub
Err_cmdDistributionForm_Click:
MsgBox Err.Description
Resume Exit_cmdDistributionForm_Click
End Sub
=========================================================
Customer Orders form OnLoad Event (Orders = Distributions)
This code is supposed to look at the existing 'products
ordered' (Distributions), and update the list box with any
items already in the database. I'm thinking this code is
not working too well, and that I haven't set it up in a
way that correctly catches the value passed from the
customer form...
==========================================================
Private Sub Form_Load()
Dim dbsSOP As DAO.Database
Dim dynRecipientsChosen As Recordset
Dim strSql As String
Dim intCurrRecipient As Integer
Dim varSOPID As Variant
varSOPID = Me.OpenArgs
'-- Open query to create list of Recipients already
assigned SOP, create dynaset
Set dbsSOP = CurrentDb
strSql = "SELECT tblDistributions.RecipientID FROM
tblDistributions" & _
"WHERE (tblDistributions.SOPID=varSOPID);"
Set dynRecipientsChosen = dbsSOP.OpenRecordset(strSql,
dbOpenDynaset)
'-- Loop through the selected choies
Do Until dynRecipientsChosen.EOF
'-- For each of the items in the listbox, see if
it matches any
'-- of the recipients already assigned the SOP
For intCurrRecipient = 0 To Me!
lboRecipientList.ListCount - 1
'-- If there is a match, mark it in the list
box as selected
If dynRecipientsChosen!RecipientID = _
Me!lboRecipientList.ItemData
(intCurrRecipient) Then
Me!lboRecipientList.Selected
(intCurrRecipient) = True
Exit For
End If
Next intCurrTable
dynRecipientsChosen.MoveNext
Loop
End Sub
========================================================
Many thanks to anyone willing to contribute suggestions to
the modification of this code.
Scott
be passed from one form to another - I tried setting this
up using the link criteria - but the form I'm launching
isn't bound to any data... I'm working on passing the
parameter using OpenArgs, but am not having much success
as of yet.
Here's a little more detail:
I'm essentially trying to set up a transaction form - not
with customers and products, but it's very similar. The
table I need to populate with this form is just like a
customer order table.
So - I have a link from the 'customer' form to
this 'customer orders' form. What I'm trying to do is
show a list of 'products' that the customer can order.
I'm using a list box to show all products on the page.
The list box uses a SQL statement as a row source,
displaying three fields (as columns) from the products
table.
Problem: I need to show as selected, any 'products' that
have already been purchased, and am trying to do so by
querying the database and finding any matches in the
customer order table. I'm thinking that this is not
working because the transaction form that contains the
list box isn't bound to any data - and am trying to pass
the key field using the button that launches the form.
Here's the code:
=========================================================
'Customer' form OnClick Event (customer = SOP)
I intend this code to launch the orders form and pass the
SOPID...
=========================================================
Private Sub cmdDistributionForm_Click()
On Error GoTo Err_cmdDistributionForm_Click
Dim stDocName As String
stDocName = "frmDistribution"
DoCmd.OpenForm stDocName, , , , , acDialog, Me!SOPID
Exit_cmdDistributionForm_Click:
Exit Sub
Err_cmdDistributionForm_Click:
MsgBox Err.Description
Resume Exit_cmdDistributionForm_Click
End Sub
=========================================================
Customer Orders form OnLoad Event (Orders = Distributions)
This code is supposed to look at the existing 'products
ordered' (Distributions), and update the list box with any
items already in the database. I'm thinking this code is
not working too well, and that I haven't set it up in a
way that correctly catches the value passed from the
customer form...
==========================================================
Private Sub Form_Load()
Dim dbsSOP As DAO.Database
Dim dynRecipientsChosen As Recordset
Dim strSql As String
Dim intCurrRecipient As Integer
Dim varSOPID As Variant
varSOPID = Me.OpenArgs
'-- Open query to create list of Recipients already
assigned SOP, create dynaset
Set dbsSOP = CurrentDb
strSql = "SELECT tblDistributions.RecipientID FROM
tblDistributions" & _
"WHERE (tblDistributions.SOPID=varSOPID);"
Set dynRecipientsChosen = dbsSOP.OpenRecordset(strSql,
dbOpenDynaset)
'-- Loop through the selected choies
Do Until dynRecipientsChosen.EOF
'-- For each of the items in the listbox, see if
it matches any
'-- of the recipients already assigned the SOP
For intCurrRecipient = 0 To Me!
lboRecipientList.ListCount - 1
'-- If there is a match, mark it in the list
box as selected
If dynRecipientsChosen!RecipientID = _
Me!lboRecipientList.ItemData
(intCurrRecipient) Then
Me!lboRecipientList.Selected
(intCurrRecipient) = True
Exit For
End If
Next intCurrTable
dynRecipientsChosen.MoveNext
Loop
End Sub
========================================================
Many thanks to anyone willing to contribute suggestions to
the modification of this code.
Scott