Referencing a combobox on another form

G

Guest

I've got a database I've been working on for the last couple weeks. It's
mostly working pretty well, but I just ran into a problem yesterday that I
can't seem to figure out. I have a main form that the user spends almost all
their time on. It's a tabbed form with several subforms on the various tabs.


Now one of these tabs has a button that pops up another form that allows
them to edit information on a contract. What I'm trying to do is grab a
couple of values from the combo boxes on the main form to pre-populate this
popup form. I suppose I could pass the key fields in and just pull the data
from the table, but I'm just wondering why this won't work, when I've done
basically the same thing in other places and it worked fine. Here's the code
that references the main form controls:

Me.txtContractNumber = [Forms]![frmContractInfo2].[Form]![cmbContract1]
Me.cmbBase = [Forms]![frmContractInfo2].[Form]![cmbBase1]

If Not IsNull(Forms![frmContractInfo2].[Form]![cmbContractType]) Then

Me.cmbContract_Type = _
Forms![frmContractInfo2].[Form]![cmbContractType].Value

End If


Ok, the first 2 lines work just fine. The error always occurs on the line
inside the If statement. The error is "Run-time error '2424': The expression
you entered has a field, control, or property name that Microsoft Office
can't find." I've triple-checked the form and control names.. several times
now, so those are right. It's strange to me that it doesn't bomb out on the
check in the If statement, but does on the line after that.

Anyone have any idea what would cause this?
 
G

Guest

If you want to refer to a combo that is placed on a main form, the path
should be

Forms![MainFormName]![ComboName]

To refer to a combo on a subform, the path should be

Forms![MainFormName]![SubFormControlName].Form![ComboName]
 
G

Guest

Ok, I changed the path to match the way you did it. Now I get a different
error on the same line:

Run-time error '-2147352567 (80020009)': The value you entered isn't valid
for this field.

The combobox on the main form is disabled and null, which is why I put the
If statement in there to check for the null value. The two questions I have
then are why is the isnull check not working, and why can't I just set the
combo on the popup form to equal the one on the main form? Null should be a
valid value for the combo, right?


Ofer Cohen said:
If you want to refer to a combo that is placed on a main form, the path
should be

Forms![MainFormName]![ComboName]

To refer to a combo on a subform, the path should be

Forms![MainFormName]![SubFormControlName].Form![ComboName]

--
Good Luck
BS"D


Bagger said:
I've got a database I've been working on for the last couple weeks. It's
mostly working pretty well, but I just ran into a problem yesterday that I
can't seem to figure out. I have a main form that the user spends almost all
their time on. It's a tabbed form with several subforms on the various tabs.


Now one of these tabs has a button that pops up another form that allows
them to edit information on a contract. What I'm trying to do is grab a
couple of values from the combo boxes on the main form to pre-populate this
popup form. I suppose I could pass the key fields in and just pull the data
from the table, but I'm just wondering why this won't work, when I've done
basically the same thing in other places and it worked fine. Here's the code
that references the main form controls:

Me.txtContractNumber = [Forms]![frmContractInfo2].[Form]![cmbContract1]
Me.cmbBase = [Forms]![frmContractInfo2].[Form]![cmbBase1]

If Not IsNull(Forms![frmContractInfo2].[Form]![cmbContractType]) Then

Me.cmbContract_Type = _
Forms![frmContractInfo2].[Form]![cmbContractType].Value

End If


Ok, the first 2 lines work just fine. The error always occurs on the line
inside the If statement. The error is "Run-time error '2424': The expression
you entered has a field, control, or property name that Microsoft Office
can't find." I've triple-checked the form and control names.. several times
now, so those are right. It's strange to me that it doesn't bomb out on the
check in the If statement, but does on the line after that.

Anyone have any idea what would cause this?
 
G

Guest

Mybe it's not Null, but empty.
Try this

If Len(Forms![frmContractInfo2].[Form]![cmbContractType] & "") > 0 Then

I used your path, change it to the path I gave you.

--
Good Luck
BS"D


Bagger said:
Ok, I changed the path to match the way you did it. Now I get a different
error on the same line:

Run-time error '-2147352567 (80020009)': The value you entered isn't valid
for this field.

The combobox on the main form is disabled and null, which is why I put the
If statement in there to check for the null value. The two questions I have
then are why is the isnull check not working, and why can't I just set the
combo on the popup form to equal the one on the main form? Null should be a
valid value for the combo, right?


Ofer Cohen said:
If you want to refer to a combo that is placed on a main form, the path
should be

Forms![MainFormName]![ComboName]

To refer to a combo on a subform, the path should be

Forms![MainFormName]![SubFormControlName].Form![ComboName]

--
Good Luck
BS"D


Bagger said:
I've got a database I've been working on for the last couple weeks. It's
mostly working pretty well, but I just ran into a problem yesterday that I
can't seem to figure out. I have a main form that the user spends almost all
their time on. It's a tabbed form with several subforms on the various tabs.


Now one of these tabs has a button that pops up another form that allows
them to edit information on a contract. What I'm trying to do is grab a
couple of values from the combo boxes on the main form to pre-populate this
popup form. I suppose I could pass the key fields in and just pull the data
from the table, but I'm just wondering why this won't work, when I've done
basically the same thing in other places and it worked fine. Here's the code
that references the main form controls:

Me.txtContractNumber = [Forms]![frmContractInfo2].[Form]![cmbContract1]
Me.cmbBase = [Forms]![frmContractInfo2].[Form]![cmbBase1]

If Not IsNull(Forms![frmContractInfo2].[Form]![cmbContractType]) Then

Me.cmbContract_Type = _
Forms![frmContractInfo2].[Form]![cmbContractType].Value

End If


Ok, the first 2 lines work just fine. The error always occurs on the line
inside the If statement. The error is "Run-time error '2424': The expression
you entered has a field, control, or property name that Microsoft Office
can't find." I've triple-checked the form and control names.. several times
now, so those are right. It's strange to me that it doesn't bomb out on the
check in the If statement, but does on the line after that.

Anyone have any idea what would cause this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top