Make default value "real"

A

Allison

Access 2003 SP3
Win XP SP2

I have a sub-form with a single combo box. The combo box is tied to a
table, and the subform is tied to a table that combines the main from ID and
the value of the combo box and creates an entry. (Relational yes/nos from
Allen Browne: http://allenbrowne.com/casu-23.html ).

I've set the default value of the combo box to "1", which displays my first
entry option (let's cal that "blue"). This displays the word "blue" but
doesn't actually capture it to the combination table in the same manner that
it would if "blue" were SELECTED, not just displayed.

Is there a way to SELECT a value by default - not just display it?
 
A

Allen Browne

Allison, I'm not 100% clear about what you want to do here.

Are you saying that every time the user enters a new record in the main
form, you want to automatically insert the 'blue' record into the subform's
table as well? If so, you could do that by executing an append query
statement in the AfterInsert event procedure of the main form.

I'm not convinced that's a good idea. Does 'blue' really apply to everyone?
There are cases where this is valid, but not as a general rule.

If that's not what you want to do, then it might be best to leave the
combo's Default Value blank, so it's obvious to the user that they must
select 'blue' if they want it.
 
J

John W. Vinson

Access 2003 SP3
Win XP SP2

I have a sub-form with a single combo box. The combo box is tied to a
table, and the subform is tied to a table that combines the main from ID and
the value of the combo box and creates an entry. (Relational yes/nos from
Allen Browne: http://allenbrowne.com/casu-23.html ).

I've set the default value of the combo box to "1", which displays my first
entry option (let's cal that "blue"). This displays the word "blue" but
doesn't actually capture it to the combination table in the same manner that
it would if "blue" were SELECTED, not just displayed.

Is there a way to SELECT a value by default - not just display it?

I agree with Allen that this seems a bit strange. A child table with only one
field, containing "Blue" in every record, seems singularly useless to me!

A Default Value applies only when a new record is created; you will need to
"dirty" the subform in some way.
 
A

Allison

Yes that's what I want to do.

Reason is - there will be separate user forms for each "default" type - so
there shouldn't be a need for the user to have to enter the type because the
fact that they're using a specific form means that it is so.

I'll look at the append function. Thanks.
 
A

Allen Browne

Okay: so there are default types to be assigned when a main record is
created. That makes sense. Executing the append query in the main form's
Form_AfterInsert is what I use for that.

If Execute is new, you can mock up an Append query, and switch it to SQL
View to see a sample of the string you need to create. Then this link
explains and provides an Execute example:
http://allenbrowne.com/ser-60.html
 
L

Linq Adams via AccessMonster.com

I've been looking at this thing off and on all day, trying to figure out what
the OP actually means. Hopefully he can confirm or deny this. From his
statement:

"I've set the default value of the combo box to "1", which displays my first
entry option (let's cal that "blue"). This displays the word "blue" but
doesn't actually capture it to the combination table in the same manner that
it would if "blue" were SELECTED"

It sounds to me as if he has some code in the AfterUpdate event of his
combobox that used to combine something with the Value of the combobox.

He's set the combobox to default to the value "Blue"

If an item is actually selected from the combobox, the AfterUpdate fires and
everything works as is hoped for

On the other hand, if the default Value of "Blue" is left in the combobox,
the AfterUpdate event doesn't fire (because the Value has been placed in the
combobox via code rather than physically selected) and the AfterUpdate event
doesn't fire, and the desired outcome doesn't occur.

If this is the problem, the OP needs to do something to force the AfteUpdate
event to fire, when the combobox Value is the same as the default Value that
it's been set to.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.ComboBox = "Blue" Then
ComboBox_AfterUpdate
End If
End Sub
 

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