Filling fields

M

Mike Geoghegan

I have a table named CODES that contains the following
fields:
MainCode field length = 8
Hex1 field length = 2
Hex2 " " "
Hex3 " " "
Hex4 " " "

I would like to enter 8 digits into the "MainCode" field
and have the form automatically take the first 2 digits
and enter them in "Hex1", then the next 2 digits
into "Hex2" and so forth.
Example:
MainCode 12345678
Hex1 12
Hex2 34
Hex3 56
Hex4 78

I can get it to enter the first 2 digits into Hex1 with
this code:

Private Sub MainCode_AfterUpdate()

Dim txtCode As String
Dim Code1 As String

txtCode = Forms!keys!MainCode.Text
Forms!keys!MainCode.SetFocus
Forms!keys!hex1.SetFocus
Code1 = Forms!keys!hex1.Text
Code1 = UCase(Left(MainCode, 2))

If Forms!keys!hex1.Text = "" Then
Forms!keys!hex1 = Code1

End If

End Sub

Can someone help me?
Thanks!
 
A

Al Campagna

Mike,
Since the MainCode always contains the information needed to fill in
Hex1-Hex4, there's no need to have those fields in your table. They can
always be "re-derived" the values "on the fly" from MainCode in any
subsequent form, query, report, etc.
An example is... if I store Price and Qty, I don't need to store
LineItemCost (Price*Qty), since I can always recalc it whenever it's needed.
In your case, 4 "unbound" calculated fields will display the Hex1-4
values.
The Hex1 ControlSource would be...
= Left(MainCode,2)
The Hex2 ControlSource would be...
= Mid(MainCode,3,2)
The Hex3 ControlSource would be...
= Mid(MainCode,5,2)
And Hex4...
= Right(MainCode,2)
 

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