Full Version: Open Args To Highlight A Field On Another Form
UtterAccess Forums > Microsoft® Access > Access Forms
lclayton1997
Need your help please!

I have a form that opens up to a specific record called Product_ID.
That field shows in the form's header and the detail shows the month(s) and quantities that shipped in that (those months).

I have code on the month so that when the user clicks on it a new form will open and show all the products that shipped for that month.

What I want to happen is when the new form opens, the record (product_ID) that I was just on is then highlighted in the new form so the user can easily see where it fell in the mix.

I am trying to use openargs but am new to that code.

this is what I have so far:

Form 1 (called F_salesmix_monthbyprod) on click of field Month:

Private Sub Month_Click()
DoCmd.OpenForm "F_SalesMix_monthly_detail", acNormal, , "month = " & Me!Month, acFormReadOnly, , OpenArgs:=Me!PRODUCT_ID
End Sub

on Form 2 (called F_salesmix_monthly_detail) on load:

Private Sub Form_Load()
Dim varargs

varargs = Me.OpenArgs

If Not IsNull(varargs) Then

With CurrentDb.OpenRecordset("select * from Q_salesmix_monthly_select where product_id = " & varargs)
Me.PRODUCT_ID = !PRODUCT_ID
Me.PRODUCT_ID.BackColor = vbRed
End If
End Sub

of course this does nothing.
What am I missing?
theDBguy
Hi. Are you getting any errors such as With Block without End With? Just curious...
lclayton1997
no errors.

but on loading the other form it just opens normally.
lclayton1997
I found this:
Sub OpenToCallahan()
DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, _
, "Callahan"
End Sub

Sub Form_Open(Cancel As Integer)
Dim strEmployeeName As String
' If OpenArgs property contains employee name, find
' corresponding employee record and display it on form. For
' example,if the OpenArgs property contains "Callahan",
' move to first "Callahan" record.
strEmployeeName = Forms!Employees.OpenArgs
If Len(strEmployeeName) > 0 Then
DoCmd.GoToControl "LastName"
DoCmd.FindRecord strEmployeeName, , True, , True, , True
End If
End Sub

Which is what I want to do...
BUT I need for the openarg not to be specified, but to point to the record Product_ID I am already in.
Also Product_ID is numeric not a string.

how would I change this code to do that?
mike60smart
Hi

Instead of using the On Click of the Month you can create a Command Button using the Wizard and specify ProductID as the Control to match
theDBguy
Hi. Let's back up a little. Are you trying to open a secondary form and want it to display information related to a record you're viewing on a separate form? If so, do you intend to navigate away from that record and view details for other records as well? If not, then you don't even need to use the OpenArgs property.
lclayton1997
That is exactly what I am trying to do.

form 1 shows product_ID 119109001 and the months in which it had sales.

I want to open another form that contains ALL product_IDs with their sales for that same month which is sorted by sales and I want the previous forms' 119109001 highlighted so I can see where it is in the new continuous form

I should add that on the previous form I am clicking on the month which opens the other form with continuous records for all products sold that month.
moke123
have you tried conditional formatting and set the rule so that productid = openargs
lclayton1997
that is what I am trying to do, but new to openargs so don't know how to pass the product_id, find it and highlight it in the new form
lclayton1997
SOLVED!
Yah! thanks Moke123

I just had the openargs written wrong and now it works like a charm!!!!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.