Solved

Populating ComboBox and refreshing subform from VB

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now