Solved

Populating ComboBox and refreshing subform from VB

Posted on 2013-06-12
3
396 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 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

770 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