By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,455 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,455 IT Pros & Developers. It's quick & easy.

Updating parent form from child form

P: 36
Hi,

First, the background info:

I have a parent form, New_Jobcard that contains a combo-box to select Cust_ID. The combobox shows customers sorted by name and address, like this:

Cust_ID V Cust_Name Cust_Addr Cust_Phone

"Cust_ID V" is the combobox.
Cust_Name... Phone are un-editable fields, from the Customers table, and the combobox shows these as columns so you can use it to choose the right Cust_ID from the name and address details.

This all works fine. I have another combobox, Unit_ID, which displays a list of the customer's previously repaired items for easy selection; when you select a customer, this combobox gets updated and displays the relevant records correctly. It's set up similarly to the Cust_ID field, with uneditable fields to the right which show the details of the selected Unit_ID, lik this:

Unit_ID V Unit_Make Unit_Model Unit_SN

This also works fine.

Now to my problem:

I have now introduced a "New" button for adding new customers: it opens the New_Customer form, so that you can put a new customer's details in, and has a "Close" button which, stuffs the new Cust_ID into the parent form's Cust_ID combo, and then makes the combobox requery. The new Cust_ID appears in the combo ok, and the new customer's details appear in the combo list, but the uneditable ("Cust_Name" etc.) fields don't get updated unless you manually select the new cust ID from the list.

I must be missing something - all I *think* I need to do is tell the combobox that a new *selection* has occurred, rather than stuffing the value directly into it. I just can't figure out how! (Maybe I'm asking the impossible, or maybe I have it all wrong, both are entirely possible).

regards,
-cybervegan
Feb 14 '07 #1
Share this Question
Share on Google+
9 Replies


NeoPa
Expert Mod 15k+
P: 31,186
To select a Row in a ComboBox from within code, simply set it to the value of the Row. To refer to items on connected forms see (Referring to Items on a Sub-Form).
Feb 14 '07 #2

P: 36
To select a Row in a ComboBox from within code, simply set it to the value of the Row. To refer to items on connected forms see (Referring to Items on a Sub-Form).
Thanks for your reply, EnoPa. Terminology, as ever, confuses the issue (me not using the right terms!). I'm not using *sub-forms* - I am using separate forms, called by an openform command button (not sure if that matters) on the "parent" form, but the advice on the link you gave seems to be more about sub-forms. I know how to address the elements of the other forms, it's just the problem of triggering the update of the parent form's data when a new record is added via the child form.

Rephrasing my question, I think what I really need to know is how to "simulate" the user selecting an item on the main form's combobox, from the subordinate form's "Close" action button, or informing the combobox control that a new value has been put into it. I'm using the .Requery method on the combo, and that works - the new record is shown in the drop-down list, but you have to select it manually: I want it to be automatically selected.

Thanks again,
-cybervegan
Feb 15 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
  • The term Parent is not correct for referring to a form which caused another form to be opened (I do understand you though ;)).
  • Any code for a Close button should preferably be handled in the OnClose event of the form. This way, an operator hitting the x at top right, will not cause it to be handled in an inconsistent manner.
  • The link also includes references to unconnected forms as well as to subforms and parent forms (Careful of the term Parent here).
  • Your OnClose event procedure can therefore set a value in the ComboBox of the calling form as well as cause it to .requery.
  • It is good coding practice to handle the possibility of the calling form not being open in your code. You don't want a crash just because the operator closed it by mistake.
Feb 15 '07 #4

P: 36
Thanks, NeoPa,

I'll give that a try. I was thinking about the possiblity of theuser just exitingthe form with the windows close - that's a great tip, thanks.

The code I have already puts the value into the combobox, and then does a .requery, however, the record is still not *selected*, and thus the table relationships are not "followed" (the informational fields do not update and contain stale data until the user manually selects the new record from the combobox list).

Is therer a way to tell the control that it's selected value has changed, as if the user had selected the new record?

thanks,
-cybervegan
Feb 15 '07 #5

NeoPa
Expert Mod 15k+
P: 31,186
Is there a way to tell the control that it's selected value has changed, as if the user had selected the new record?
If you're asking about a ComboBox then yes.
You assign the new required value to it.
Expand|Select|Wrap|Line Numbers
  1. cboRecord = "New Record Value"
Feb 15 '07 #6

P: 36
If you're asking about a ComboBox then yes.
You assign the new required value to it.
Expand|Select|Wrap|Line Numbers
  1. cboRecord = "New Record Value"
Yes, as I said, I'm doing exactly that, but it doesn't *select* the record, and it doesn't follow relationships and update the display corresponding fields on the form. That only happens if you manually click on the entry in the drop-down box - the display fields are then updated correctly. Assigning it a value does not have the same effect :-(

I'm looking at doing this a different way - using a procession of selection forms, wizard-style, with the selections ending up on the final form. Not exactly what I had in mind, but...

regards,
-cybervegan
Feb 16 '07 #7

NeoPa
Expert Mod 15k+
P: 31,186
Sorry to hear that.
I guess I haven't used it exactly the way you do before, but I often have to set a default value depending on other selections on a form and that's always worked for me.
Feb 16 '07 #8

P: 36
I have a solution.

(Ghasp!)

Instead of using bound fields to show the details for the currently selected cust_id, i am now using unbound fields and populating them via dlookup() in the OnClick and OnChange event procs of the combobox and the "New Customer" button. The form's OnLoad procedure clears the values (this is a data entry form).

It's more work, but it does what i want, which is provide user-feedback that the newly entered customer record has been correctly saved and selected.

-cybervegan
Feb 21 '07 #9

NeoPa
Expert Mod 15k+
P: 31,186
Sorry I couldn't help more.
I admit to being a bit confused by your responses - what I understand you to be saying doesn't fit with my understanding of how things work. That could be for any number of reasons though. I'm not fool enough to think I know all there is to know, so there could just be something I'm unaware of.
Personally I'd want to find and fix whatever problem you're having, but that's just not practical in the current circumstances, in the dark as I am (not blaming you for this - just what you get sometimes dealing at second-hand) as to what exactly is going on. In the circumstances you need to go with whatever you can get to work.
Hopefully we can give you a better response time you call on us for help.
Feb 22 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.