Using Value in Text box as default value

H

Harry Bo

Hi

I have an unbound text box (Text34) in the form header.

I have field in the form (Business Unit) formatted as Text and uses a cbo from tblBunit ( only 5 units).

When the user enters data, they normally do so via an invoice that is specific to a business unit. So to get around typing CRT01234 100's of times, if I type it once into text box (Text34) it becomes the default. Then when I come to business unit CRT01556, I simply type this into the same txt box.

How do I do this?

I've tried setting the properties default to the text box (=txt[Text34], but it only updates when I go from form view to design view and back to form view.

Thanks

Harry
 
A

Allen Browne

Use the BeforeUpdate event procedure of the form to assign the value in the
text box to the combo:

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Text34) Then
Me.cboXXX = Me.Text34
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Harry Bo said:
I have an unbound text box (Text34) in the form header.

I have field in the form (Business Unit) formatted as Text and uses a cbo from tblBunit ( only 5 units).

When the user enters data, they normally do so via an invoice that is
specific to a business unit. So to get around typing CRT01234 100's of
times, if I type it once into text box (Text34) it becomes the default. Then
when I come to business unit CRT01556, I simply type this into the same txt
box.
How do I do this?

I've tried setting the properties default to the text box (=txt[Text34],
but it only updates when I go from form view to design view and back to form
view.
 
H

Harry Bo

Allen,

Thanks for the reply.

How do I enter this into this into thr event procedure?
and how do I know the name of the combo box?

Thanks again

Harry

Allen Browne said:
Use the BeforeUpdate event procedure of the form to assign the value in the
text box to the combo:

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Text34) Then
Me.cboXXX = Me.Text34
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Harry Bo said:
I have an unbound text box (Text34) in the form header.

I have field in the form (Business Unit) formatted as Text and uses a cbo from tblBunit ( only 5 units).

When the user enters data, they normally do so via an invoice that is
specific to a business unit. So to get around typing CRT01234 100's of
times, if I type it once into text box (Text34) it becomes the default. Then
when I come to business unit CRT01556, I simply type this into the same txt
box.
How do I do this?

I've tried setting the properties default to the text box (=txt[Text34],
but it only updates when I go from form view to design view and back to form
view.
Thanks

Harry
 
A

Allen Browne

Hi Harry. Not sure I have understood what you are trying to do.

Are you saying you have *hundreds* of combo boxes in this invoice? If so,
there is a serious problem with the data structure.

Instead of creating hundreds of combos for all the possible values (and
still being stuck when you need to add a new one), consider breaking this
table down into two: one the the invoice header, and another for the
details. The Northwind sample database gives you an example of this - Orders
and OrderDetails tables.



--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Harry Bo said:
Allen,

Thanks for the reply.

How do I enter this into this into thr event procedure?
and how do I know the name of the combo box?

Thanks again

Harry

Allen Browne said:
Use the BeforeUpdate event procedure of the form to assign the value in the
text box to the combo:

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Text34) Then
Me.cboXXX = Me.Text34
End If
End Sub

Harry Bo said:
I have an unbound text box (Text34) in the form header.

I have field in the form (Business Unit) formatted as Text and uses a
cbo
from tblBunit ( only 5 units).
When the user enters data, they normally do so via an invoice that is
specific to a business unit. So to get around typing CRT01234 100's of
times, if I type it once into text box (Text34) it becomes the default. Then
when I come to business unit CRT01556, I simply type this into the same txt
box.
How do I do this?

I've tried setting the properties default to the text box
(=txt[Text34],
but it only updates when I go from form view to design view and back to form
view.
Thanks

Harry
 
A

Allen Browne

To find out the name of your combo box:
1. Open your form in design view.
2. Right-click the combo, and choose Properties.
3. Look at the Name property (first item on the Other tab of the Properties
box).

To enter the code:
1. Choose the properties of the *form*, not a control.
2. On the Event tab of the Properties box, locate the Before Update
property.
3. Enter:
[Event Procedure]
4. Click the Build button (...) beside this.
Access opens the code window.
5. Place the 3 lines of code in the event procedure.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Harry Bo said:
Allen,

No I have one cbo with 5 entries:
CRT:
01234
01278
01556
06633
07112

Need to know how you name the combo box and where I put the code.

Thanks Harry

Allen Browne said:
Hi Harry. Not sure I have understood what you are trying to do.

Are you saying you have *hundreds* of combo boxes in this invoice? If so,
there is a serious problem with the data structure.

Instead of creating hundreds of combos for all the possible values (and
still being stuck when you need to add a new one), consider breaking this
table down into two: one the the invoice header, and another for the
details. The Northwind sample database gives you an example of this - Orders
and OrderDetails tables.



--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Harry Bo said:
Allen,

Thanks for the reply.

How do I enter this into this into thr event procedure?
and how do I know the name of the combo box?

Thanks again

Harry

:

Use the BeforeUpdate event procedure of the form to assign the value
in
the
text box to the combo:

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.Text34) Then
Me.cboXXX = Me.Text34
End If
End Sub


I have an unbound text box (Text34) in the form header.

I have field in the form (Business Unit) formatted as Text and
uses a
cbo
from tblBunit ( only 5 units).

When the user enters data, they normally do so via an invoice that is
specific to a business unit. So to get around typing CRT01234 100's of
times, if I type it once into text box (Text34) it becomes the
default.
Then
when I come to business unit CRT01556, I simply type this into the
same
txt
box.

How do I do this?

I've tried setting the properties default to the text box (=txt[Text34],
but it only updates when I go from form view to design view and back
to
form
view.

Thanks

Harry
 

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