Tieing unbound subform to main form

G

Guest

Hi

I have a main form (single view) and an unbound subform (continuous)

I can select a record on the subform and have the main form go to the
corresponding record.

Is there a way to do this the other way around?
So for example if the main form was on a record with ID = 123
The subform would have this record (ID = 123) selected on the continuous form

Also

A slight inconvenience to users which I can’t seem to work out.
When selecting a record on the subform and going to the corresponding record
on the main form – the subform requerys. Why? (I have not a clue – there are
no requerys anywhere on this form set). Not really a big problem but users
have asked me to look into it as they don't want to scrool down to find the
record again (mind you if I can sort out the top question this should answer
this one as well ?) – and to tell the truth I’m lost with this. Any ideas
would be really helpful

Many thanks
 
G

Guest

I's OK - I worked it out. Not very elegent but it works. Posted here in
case anyone else want to do the same (tie an unbound subform to a main signle
form)

1st create an unbound control on the main form (hiddentxt). I use this to
accept the ID from the subform (onclick). This code then force the subform
to stay on the same record - as it will normally requery.


Private Sub hiddentxt_GotFocus()
DoCmd.SetWarnings False
Dim RS As Object
'this section forces the main form to a specific record'
Set RS = Me.Recordset.Clone
RS.FindFirst "[ID] = " & Str(Nz(Me![hiddentxt], 0))
If Not RS.EOF Then Me.Bookmark = RS.Bookmark
'this section move the focus on the subform to the same as the main form'
Set rst = Me("SubFormName").Form.RecordsetClone
rst.FindFirst "ID = " & ID
Me("SubFormName").Form.Bookmark = rst.Bookmark
End Sub


Good luck
 
D

Dirk Goldgar

In
Wayne-I-M said:
Hi

I have a main form (single view) and an unbound subform (continuous)

By unbound, I think you mean what I would call "unlinked"; that is, the
Link Master/Child Fields are blank. Yes?
I can select a record on the subform and have the main form go to the
corresponding record.

Is there a way to do this the other way around?
So for example if the main form was on a record with ID = 123
The subform would have this record (ID = 123) selected on the
continuous form

Is this the sort of thing you're looking for?

'----- start of example code (for main form) -----
Private Sub Form_Current()

If Me.NewRecord Then

' Not sure what you want the subform to do here.

Else

With Me!Subform1.Form.RecordsetClone
If !ID = Me.ID Then
' Don't move; we're there.
Else
.FindFirst "ID = " & Me.ID
If Not .NoMatch Then
Me!Subform1.Form.Bookmark = .Bookmark
End If
End If
End With

End If
'----- end of example code -----
Also

A slight inconvenience to users which I can't seem to work out.
When selecting a record on the subform and going to the corresponding
record on the main form - the subform requerys. Why? (I have not a
clue - there are no requerys anywhere on this form set). Not really
a big problem but users have asked me to look into it as they don't
want to scrool down to find the record again (mind you if I can sort
out the top question this should answer this one as well ?) - and to
tell the truth I'm lost with this. Any ideas would be really helpful

That seems strange, if the subform is truly unlinked. Are you sure?
What code are you using in the subform to force the navigation in the
main form? And is there some code in the main form's Current event that
would force the requery (such as changing the subform's RecordSource)?
 
G

Guest

Hi Dirk

Thanks for the idea. The form(s) are "a little mad" :) as they are
designed to the users spec and not mine. I thought I would give it a try
(just this once LoL).

Anyway I got it to work - I am just waiting for the next request

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top