Solved

Populating ComboBox and refreshing subform from VB

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 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

9 Experts available now in Live!

Get 1:1 Help Now