Hi Jessica,
Have you noticed that we've slipped to page 27 already!
So you've been using Access for 10 years. If any of my pedantic
explanations are belittling then I apologise; it is always dificult to know
at what level to pitch a response and I always lean toward over-explanation.
Could I recommend that you obtain an Access reference - not a 'Teach
Yourself' or a 'Beginners' text but something that includes VBA as well as
the standard Access objects. I think you're ready for it. As for using the
correct terms there are so many conventions out there that anarchy and
confusion reign: in certain contexts 'array' and 'table' are synonymous, in
others 'table' and 'file'; when referring to tables 'fields', 'columns, and
'attributes' are used interchangeably. I could go on.
Public Event NewID(lngIDNum as long) should cause no error. If you remove
the 'as long' phrase Access will treat lngIdNum as a variant. (I assume
lngIDNum is not defined anywhere else in your project.) What's it for? The MS
help for user events states that you cannot use an event to pass values
whereas the mechanism gives you just that functionality: you can pass as many
values/parameters/arguments as you wish and these are defined in the Publlic
Event statement within parentheses. So in this case there is one argument
named lngIDNum. You set it's value when you use the RaiseEvent statement and
that value becomes available in any event-handler that you code in the
'listening' object. Specifically I suggested it to pass the primary key of
the line being double-clicked. The parent form could, of course, look back at
the sub form and obtain the value directly but I chose a parameter because it
seemed 'cleaner.' (There are many ways to skin a cat - perhaps that's why
they have nine lives.)
OK on to your main concern. In your 'listening' form you will have an event
handler as a procedure defined something like Private Sub
xxxxxxx_NewId(lngIDNum) where xxxxxxx is the name you used in the WithEvents
statement in the declaration section. I originally suggested use of the
Filter property to synchronise your form but then realised that it would
inhibit navigating away from the record(s) matching the filter.
The best way of positioning a recordset at a particular record is to use a
find method on a clone of the recordset. Why use a clone, after all you could
do it on the recordset itself? Well the search goes on 'behind the scenes'
and Access does not have to continually update the form display and the
chance of the user getting a migrane is reduced. So in this event handler
code something like the following (this is the DAO solution).
Dim rstClone as DAO.Recordset
Set rstClone = Me.RecordsetClone 'Note RecordsetClone is all one word
rstClone.MoveFirst 'Position at first record ready for search
rstClone.FindFirst "IDNum = " & lngIDNum 'Here we use the event value
If rstClone.NoMatch then
Exit Sub 'or take whatever other action necessary
Else
Me.Bookmark = rstClone.Bookmark 'Now position form at desired record
End If
Avoid solutions using GoToRecord - it's somewhat 'clunky.' VBA developers
brought forward many of the Access menu and toolbar actions into VBA as
methods. Most reside in the DoCmd object. These methods simulate the Access
commands. By that very definition they have to be less efficient and
possibly more restrictive than the 'native' VBA methods.
Regards,
Rod
Dim rstClone as DAO.Recordset
Dim frmMain as Access.Form
Set frmMain = Me.Parent 'Should trap error 2452 here and exit
Set rstClone = frmMain.RecordsetClone 'Note RecordsetClone is all one word
rstClone.MoveFirst 'Position at first record ready for search
rstClone.FindFirst "IDNum = " & Me.IDnum 'Here Me is the subform
If rstClone.NoMatch then
Exit Sub 'or take whatever other action necessary
Else
frmMain.Bookmark = rstClone.Bookmark
End If