Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Populating ComboBox and refreshing subform from VB

Posted on 2013-06-12
3
Medium Priority
?
405 Views
Last Modified: 2013-06-13
Dear experts

I am really struggling with an issue which I am sure someone can fix for me.

I have prepared a simplified database (attached) that should show the problem.

The database as it is at the moment has 2 objects (Groups and Contacts)
A group can have a contact assigned, but only those that are designated as valid for that group.

When creating or editing a group, the contact is selected from a ComboBox.  In the case of a new Group, the ComboBox would of course be empty.  So there is a “New Contact” button that allows to add a new contact for the group.  In the case of editing a Group, there is also a requirement to add a new contact, so the New Contact button is also required there.

I am not using the ComboBox option “List Items Edit Form”, because this application needs to work under Access  2003 as well.

My problem is that, when the frmAddMainContactToList closes (using the Save button) the comboBox on the main form is not populated with the new ContactID and the subform showing the contact details is not refreshed.
I hope this is a clear enough explanation.

Regards

Richard
Simplified-database---EE-120613.mdb
0
Comment
Question by:rltomalin
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 39241226
Firs things first: If the app must work with 2003, then you would be STRONGLY advised to actually develop it in 2003. From your earlier question I assume that you're using a later version, like 2007 or 2010. There can be (and normally are) issues with non-trivial applications developed in 2001/2010 and then deployed to users with 2003.

If I recall, you goal in this matter is to be able to add a New Contact to an existing Group, by the user selecting a value in the combo, or by clicking your "New Contact" button. Is that correct?

I believe your issue stems from the way you're using the Master and Child link fields for your subform. You've linked both GroupID and ContactID, and you shouldn't do that - since that limits your subform's Recordsource to a single record (assuming the combination of GroupID and ContactID represent a unique record, of course).

Instead, try linking on ONLY GroupID form both Master and Child links, and then using code in the main form's Current event to "set" the value in the MainContact subform:

Private Sub Form_Current()

    Dim rst    As DAO.Recordset
    Set rst = Me.MainContactDetails.Form.RecordsetClone

    rst.FindFirst "ContactID=" & Me.MainContactID

    If Not rst.NoMatch Then
        Me.MainContactDetails.Form.Bookmark = rst.Bookmark
    End If

End Sub

Open in new window


To manage the New Contact stuff, you'll need to make some changes in the way your popup form interacts with the "main" form. In essence, you'd do this:

1) Add a new property to frmAddMainContactToList to store the "current" contact.
2) Open your popup form as a Dialog form
3) In the popup form, "set" the property from Step1 when it closes
4) Now back in frmAddMainContactToList, use the value set in Step 3 to sync your combo and subform.

I've made some changes and reattached your sample.
Simplified-database---EE-120613.mdb
0
 

Author Comment

by:rltomalin
ID: 39241339
Thanks LSM
I will look at this tomorrow now.

Regards

Richard
0
 

Author Closing Comment

by:rltomalin
ID: 39243778
Hi LSM
Thank you - that seems to have fixed it.  I am having a bit of a problem figuring out exactly why it works because it is using code that I am not familiar with.  But I will work my way through and introduce the tecniques to me application and then hopefull it will work.

Regards
Richard
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question