open last record in a subform

jammyp

Registered User.
Local time
Today, 14:02
Joined
Jan 26, 2005
Messages
34
Hi,
I have a form, with a subform in it.
I am trying to add a record through the subform then once added I want to display that record..
at the moment I add the record but the first record is shown.

I have tried adding :

DoCmd.GoToRecord , Forms!frmviewscheme![QScheme_Establishment subform], acLast

but recieve a run-tim error 2498.

can anybody help me ?

regards,
Ja
 
when you add the record, something like

subdetails.requery (if you are in the main form) or
me.requery (if you are in the subform)

should requery the record source, and add the new record to the subform.

if you popup a form to enter the newrecord you may need to pause the subform until the popform is close, and only then do the requery
 
hi, how do I do the pause you mention ?

I have formA
then in there formB
I click a button on formB to open formC to add the record.
formB needs to then show the last record...
 
Hi,
just to let you know , I want to show the newly added record..
I can add the record, so starts showing 1 or 10 records, then it is added and shows 1 of 11. but I want to automatically display record 11..
If it is one form it works, but I can't get it to work with subforms..

thank you.
 
assuming you are using docmd.openform you need

Code:
docmd.openform "popupform"

[COLOR="Blue"]'this is the extra bit[/COLOR]
while isopen("popupform")
   doevents
wend

'this loops round until you close the "popupform"
'so now you can do requery the form, to pick up any new records you added, and if necessary move to the last record

Code:
me.requery
application.runcommand acCmdRecordsGotoLast

'put this in a module for the isopen test
Code:
Function IsOpen(strName As String, Optional objtype As Integer = acForm)
IsOpen = (SysCmd(acSysCmdGetObjectState, objtype, strName) <> 0)
End Function
 
hi, thank you thats brilliant, although where does the requery bit go > in formb or formC ?
 
me.requery will requery whichever form you are in, by reextracting the records in the source query.

the idea is

...running code in form 1

...open another form 2

...doevents until form 2 is closed

...now requery form 1, in case new records were added


hope this makes sense
 
hi, yes it makes sense, cheers.
problem is I am now receiving the error, you can't go to the specified record when trying to goto the last record..
I hate access. :o)
 
hi, ignore that last message. this works fine.
(I had the aclastrecord command in 2 places).

Thank you so much for all your help..
 

Users who are viewing this thread

Back
Top Bottom