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

SubForm HELL! 2

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
I have a Form called Clients. It is bound to the table Clients. It has a Tab Control on it. The first page(tab) contains all the fields in the Clients table.

I want the second page to display the fields from another table called Contacts. To this end I have put a SubForm onto the second page, whose Source Object is a Form called "Demo" which displays all the fields in the Contacts table.

The "Demo" form has a list box on it which when you click on a name it populates all the other fields on the Form with data. Although it works fine as a "stand-alone" form, when it is included within the "Clients" tab control I get a "..could not find the Form 'Demo'..." error.

Below is the code that is behind the ListBox click event:

Set DB = CurrentDb
Set MyRs = DB.OpenRecordset("Contacts", dbOpenDynaset)

strCriteria = "[ContactID]= " & (Me!List2) & ""

MyRs.FindFirst strCriteria

Forms!Demo.Bookmark = MyRs.Bookmark

MyRs.Close

It falls over on the Bookmark line. I have tried referencing it Forms!formname!subformname.Bookmark but get a "Object does not support this property" error. Can someone be my knight in shining armour...?
 
It won't find "Forms!Demo" because 'Forms!Demo' is not open

You need

"Forms!Client!SubFormControlName.Form"

instead.


'ope-that-'elps.

G LS
 
Further to my last question is it possible to open and close a SubForm whilst keeping the Main host form open?
 
You can't open and close it as such.
You can change it to another form with

Forms!frmmain!frmContent.SourceObject = "frmWelcome"

or you could probably hide it (not sure tho, never tried it)

Forms!frmmain!frmContent.Visible=False


Enjoy

Ben
 
Thanks Ben for your reply but it doesnt seem to have the required effect. Basically whats happening is that when I delete a record and then try to access the record that has now taken it's place in the ListBox ordering I'm getting a:

3167 Error - Record is Deleted.

The purpose of opening and closing the Form was to refresh the recordset and thus avoid the occurence of this error.

Any ideas...?
 
Don't Open and Close - just REQUERY

In code following the delete add:-
ListBox.Requery

that will do it for you.

You can Requery controls or Forms. But remember that if you requery a Form you reset the pointer to the first record in the sort order unless you do something with bookmarks or GotoRecord, FindRecord etc


'ope-that-'elps.

G LS
 
Smudger you are a diamond! I was already using the List1.Requery command with no success. However the Form.Requery works a treat.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top