Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form OpenArgs Questions

Status
Not open for further replies.

henlov

Technical User
Nov 1, 2007
2
US
I have a button on the main form, Form1, that opens another form, Form2, to the same record as the first form.

This code works fine when using the main table. The primary key is ID. I want to sort the data in the main table by Field1 using a query, Query1, and open Form2. I tried to change the the code as shown below, but in this case Form2 opens at the first record in the query, not to the record in Form1. For example if Form1 is at record 100, Form2 will show record 1.
Maybe someone knows how to make it work. Thanks.

Private Sub btnOpenMulti_Click()
DoCmd.OpenForm "Form2", OpenArgs:=" WHERE ID >= " & [ID]

' Changed to: DoCmd.OpenForm "Form2", OpenArgs:="[Field1]"

End Sub

Form2

Private Sub Form_Load()

' Open the recordset and update the controls
CurrentPage = 1

Set cn = CurrentProject.Connection
Set rst = New ADODB.Recordset

With rst
.PageSize = 8
.ActiveConnection = cn
.Source = "SELECT * FROM Form1" & Me.OpenArgs

' Changed to: .Source = "Query1 '" & Me.OpenArgs & "'"

.LockType = adLockOptimistic
.CursorType = adOpenStatic
.Open
End With

UpdateControls
End Sub
 
You could change the Openargs to hold only the ID. This would allow you to find the record after sorting.
 
How are ya henlov . . .

Be aware, OpenArgs only accepts a string. If your ID is numeric you'll have to perform two conversions. In any case here's the method:
Code:
[blue]Private Sub btnOpenMulti_Click()
    DoCmd.OpenForm "Form2", OpenArgs:=[purple][b]CStr([/b][/purple]Me!ID[purple][b])[/b][/purple]
End Sub


Private Sub Form_Load()
   Me.RecordsetClone.FindFirst "[ID] = " & [purple][b]Val([/b][/purple]Me.OpenArgs[purple][b])[/b][/purple][/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Thanks for the reply. I will work with this.
 
henlov
I think you will find that, as you are dealing with strings, it will not be necessary to convert ID if it is a number, however, you will need delimiters, if it is not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top