requery combobox in subform (1 Viewer)

kgcrowther

Registered User.
Local time
Today, 06:13
Joined
Jun 1, 2001
Messages
52
This topic has been discussed, but I can't seem to apply any of the responses to my problem.

I have a combo box in a subform. It queries a table with employee information. When you enter something not in list or double-click on the box it brings up the employee info table to add an employee. After they add there employee I'd like them to be able to see that new employee in the combo box. It seems simple enough, but I can't get it to work.

I started by putting a requery command in the OnGotFocus event. I figured after the other form opens, and then closes the OnGotFocus event would work. Anyway I tried many different ways to requery it.

I tried:

Me.Requery
Me.fieldname.requery
Me.subform.requery
me.subform.refresh
Me![mainFormName].[subFormName].requery

etc. etc. etc. I also tried all these in the OnClick event figuring that you had to click the combo box to view the item. I don't understand what I'm doind wrong.

Any ideas??

Kenneth
 

charityg

Registered User.
Local time
Today, 06:13
Joined
Apr 17, 2001
Messages
634
You should put the requery command in the afterupdate event of the form that is used to add the new employee. The new employee won't show in the drop down until it has actually been added to the underlying datasouce. If you are entering directly into the table, I would recommend that you create a form to handle the data entry.
 

kgcrowther

Registered User.
Local time
Today, 06:13
Joined
Jun 1, 2001
Messages
52
I think that I might be referencing the subform control incorrectly.

I first tried:

Forms![MainFormName]![SubFormName].Form![ControlName]

It gives an error that says, "Cannot find the field called 'SubFormName'"

When I try to reference it:

Forms![MainFormName]![ControlName] it gives me the same error (except it can't find the field name 'ControlName'

When I try:

Forms![SubFormName]![ControlName] it gives the error that it can't find the form. Why can't it find the control in the subform. I don't understand.

Kenneth
 

Carol

Registered User.
Local time
Today, 06:13
Joined
Jan 15, 2000
Messages
280
Substitute the names to the ones actually contained within your form, example:

If your form is called Employees, substitute this for the MainFormName.

If your field is called EmployeeID, substitute this for the ControlName, etc.
 

kgcrowther

Registered User.
Local time
Today, 06:13
Joined
Jun 1, 2001
Messages
52
I understand this. I was just giving an example of the sytax that I was using so that you could differential between what I was calling a form name, subform name, etc.
My point was that this syntax is not working and I don't understand what is wrong. I've checked everything for spelling errors. If this syntax is correct then my error might be somewhere else.

Thanks though.
 

Rich@ITTC

Registered User.
Local time
Today, 06:13
Joined
Jul 13, 2000
Messages
237
Hi kgcrowther

It's perhaps worth checking the settings for the subform name. I believe that the usual syntax is as follows:

Me.[SubFormName].[ControlName]

though these also ought to work:

Forms![MainFormName]![SubFormName]![ControlName]

Forms![MainFormName]![SubFormName].Form![ControlName]

However, none of these will work if the subform has been named automatically by Access as a control within the main form. When you add a subform to a main form Access allocates a name like Child19 - the Child part is the type of control and the number is purely a simple sequential number (so you have already added, in total, 18 other labels, text boxes, combo boxes etc).

What sometimes happens is that the subform is correctly referenced/sourced in the Control Source property, but the actual Control Name of that subform within the main form is something like Child19 - so to get this to work you would need one of the following:

Me.[Child19].[ControlName]

Forms![MainFormName]![Child19]![ControlName]

Forms![MainFormName]![Child19].Form![ControlName]

or to change the name of the control from Child 19 to SubFormName (which would seem to be easier/more sensible).

HTH

Rich Gorvin


[This message has been edited by Rich@ITTC (edited 07-24-2001).]
 

kgcrowther

Registered User.
Local time
Today, 06:13
Joined
Jun 1, 2001
Messages
52
Thankyou. That's what I was missing. I guess there are a lot of details that I seem to miss, but I'm getting better.

Thanks to all of you for your help.

Kenneth
 

Users who are viewing this thread

Top Bottom