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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set focus to specific record on continuous subform 1

Status
Not open for further replies.

xicana

Technical User
Dec 11, 2003
100
US
Access 2002

I have a database that stores PriceLists. My main form contains the header information and the subform contains the detail information (the actual items on the list). I have a "drilldown" button in the detail section of the continuous subform which when clicked pops up a seperate form in which they can view/edit information pertaining to that particular item. When they hit the "close" button on the pop-up form, the main form refreshes(to reflect any changes), the focus is set to the subform and the pop-up form closes.

My problem is that when the form refreshes, the focus on the subform goes to the first record on the continuous form. I would like the focus to return to the record that was just viewed/edited.

I know that I must somehow bookmark the current record using the record's primary key when the "drilldown" button is clicked and then somehow return focus to the bookmarked record just not sure how to do this.



Sandy
 
How are ya xicana . . .

Why an additional pop-up to edit the subform, instead of editing the subform directly?

If your only editing the items on the subform, you only need to requery the subform. Anyway here's the idea:
Code:
[blue]   Dim hldID As String, Cri As String
   
   hldID = Me![purple][b]PrimaryKeyName[/b][/purple] [green]'Hold the primarykey of the record.[/green]
   [green]'Your code to open pop-up MODAL!
   'Do not include refresh!!![/green]
   Me.Requery
   Cri = "[[purple][b]PrimaryKeyName[/b][/purple]] = [red][b]'[/b][/red]" & hldID & "[red][b]'[/b][/red]"
   Me.Recordset.FindFirst Cri[/blue]
Special Note: If your [purple]PrimaryKeyName[/purple] is numeric, remove the two single quotes in [red]Red[/red] . . .

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

Be sure to see thread181-473997
Also faq181-2886
 
Thanks for the response.

First off, I have a pop-up form to edit info because my subform only displays a select few important fields. The pop-up shows additional information.

Will the code following the me.requery in your example wait until my pop-closes to execute?





Sandy
 
xicana said:
[blue]Will the code following the me.requery in your example wait until my pop-closes to execute?[/blue]
If your opening the pop-up modal . . . Yes!

Post the code in the button along with the name & type(text, numeric) of the PrimaryKey field/control . . .

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

Be sure to see thread181-473997
Also faq181-2886
 
Thanks TheAceMan1!

I had to remove the single quotes around my criteria (my primary key is actually a long integer) for it to work.

I didn't have the modal property set to 'yes' but it still worked. I went ahead and set it to 'yes' just in case.

Thanks again!



Sandy
 
Hello,
I have a problem that is very similar to xicana's. The only difference is, there are a combination of 3 fields that make a record unique in my database rather than just one field holding a unique record ID. These 3 fields are all character data types. I attempted to put all 3 fields in the hldID variable as follows:

hldID = propertyID&scenariotype&scenarioID

but got a Compile error Expected end of statement message. Does anyone have any recommendations on how to use a combination of 3 fields as a unique record identifier to get the form to return to that record after requerying the data?

Thanks in advance.
 
I'm not too familiar with findfirst but I did a quick search on findfirst + multiple criteria on google and found that if you use the AND operator then it may work, however you may have to first hold the three different primary key fields seperatly:

hldID1 = propertyID
hldID2 = scenariotype
hldID3 = scenarioID

and then your search criteria would be something like the following:

Cri = "[FirstPrimaryKeyName] = '" & hldID1 & "'" & _
" AND " & "[SecondPrimaryKeyName] = '" & hldID2 & "'" & _
" AND " & "[ThirdPrimaryKeyName] = '" & hldID3 & "'"

Me.Recordset.FindFirst Cri

I haven't tested this...but I know I like to get ideas on what to try...let us know if it works or if you can manipulate it to work.







Sandy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top