Set default setting to combo box in another form on open

G

Guest

I am trying to set the default setting for 2 combo boxes to the value in
another form when the new form opens.

they are both text fields.
 
G

Guest

Fipp,

Note that the following code will fail if the other form is not open when
you open the "new" form. Below are two ways to handle this:

' On Open code (Method 1)
On Error Resume Next
' If other form is not open, will ignore error and continue with the next
statement

Me![MyFirstComboBox].DefaultValue = Forms![MyOtherForm]![MyControl]
Me![MySecondComboBox].DefaultValue = Forms![MyOtherForm]![MyControl]
.....<other On Open event code>

' On Open code (Method 2)
' If other form is not open, code is skipped

If If CurrentProject.AllForms("YourForm").IsLoaded Then
Me![MyFirstComboBox].DefaultValue = Forms![MyOtherForm]![MyControl]
Me![MySecondComboBox].DefaultValue = Forms![MyOtherForm]![MyControl]
End If
.....<other On Open event code>

'End Function

Hope that helps.
Sprinks
 
G

Guest

in the text box I am seeing

#name?

any ideas what might be causing that?

The form is filtered and there aren't any records yet so I want the first
record to be the values from the other forms text box's and I want the
default value to be set to that same text box.
 
G

Guest

Fipp,

This error can occur when the ControlSource is self-referential, such as, in
a control named City:

= [City] & ", " & [State] & " " & [Zip], it refers to itself.

This can also be triggered by an incorrect spelling or reference to controls
named in the ControlSource, or an ambiguous reference caused by a form
control named the same as a field in the form's underlying RecordSource. For
the latter reason, it is standard practice to rename all form controls by a
naming convention. The most accepted convention uses a 3-character prefix to
ID the control type, followed by the name of the field to which it's bound,
or a meaningful descriptor if it is Unbound--e.g., txtAddress, cboEmployeeID,
chkActive, etc.

It's difficult to tell from what you've said what might be causing the
problem. Please post:

- The names & ControlSources of both combo boxes on the new form.
- The name of the first form
- The name & ControlSource of the control on the first form that has the
value you'd like to use to set the DefaultValue properties of the new form's
controls.
- Your OnOpen event procedure code

Sprinks
 

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