Populating the data of two Textboxes into One textbox

F

FA

How can i populate the data of two fields in one field.

I have a main form Form1 with a subform Form2.
Form1 has two textboxes txtbox1 and txtbox2. On form load event i want
to populate both of them into a textbox on a subform Form1 called
txtbox3. How can i do this? I tried to use the link Child and Master in
the subform property window but i can only link one field from the main
to subform form control but iwant to link both text boxes from main
form to one textbox in the subform. I guess i need some heavy duty VBA
codes in order to acheive this?

Please help me out freinds

Moe
 
G

Guest

Hi,
not sure why you are doing this, but you can try this on the on load event:

Me!Subform.Form!ControlName.Value = Me.YourControl01 & " " & Me.YourControl02

HTH
Good luck
 
F

FA

Thanks Oliver i tried it and it did not work. The reason why i am doing
this is the value of txtbox3 is composed of the value of txtbox1 and
txtbox2. txtbox1 and txtbox2 are on the main form and txtbox3 should
take both values to form its field value.
The sample value of txtbox3 of the subform Form2 would be ('value of
txtbox1''value of txtbox2)

If there is any other way of doing this please let me know.

Thanks

Moe
 
J

John Vinson

Thanks Oliver i tried it and it did not work. The reason why i am doing
this is the value of txtbox3 is composed of the value of txtbox1 and
txtbox2. txtbox1 and txtbox2 are on the main form and txtbox3 should
take both values to form its field value.
The sample value of txtbox3 of the subform Form2 would be ('value of
txtbox1''value of txtbox2)

If there is any other way of doing this please let me know.

If you set the Control Source of txtbox3 to

=[txtbox1] & [txtbox2]

you should get what you are asking for.

If you are trying to store the contents of txtbox3 into a Table field
- don't. It's redundant, it's non-atomic, and it simply should NOT
EXIST as a table field.

John W. Vinson[MVP]
 
F

FA

Actually txtbox3 is bound to datasource field3. i want to populate the
values of txtbox1 and txtbox2 together combined in txtbox3 and save as
a new record for this field3. so for example lets say if the value of
txtbox1 is ABCDE and the value of txtbox2 it 01/01/2006. i want to
combine those values and populate them into txtbox3 as ABCDE01/01/2006.
And then save as a new record for field3.

Is this achievable??

Please help

Moe
 
J

John Vinson

Actually txtbox3 is bound to datasource field3. i want to populate the
values of txtbox1 and txtbox2 together combined in txtbox3 and save as
a new record for this field3. so for example lets say if the value of
txtbox1 is ABCDE and the value of txtbox2 it 01/01/2006. i want to
combine those values and populate them into txtbox3 as ABCDE01/01/2006.
And then save as a new record for field3.

Is this achievable??

Well...yes, with some minor difficulty. Set the value of txtbox3 in
either the Form's BeforeUpdate event, or in BOTH the txtbox1 and
txtbox2 AfterUpdate events.

BUT!

This field is SIMPLY WRONG. It should *not exist*. Fields should be
"atomic" - having only one value; yours has two. Fields should be of
one datatype - yours has two, text and date. Fields should not be
redundant - yours is redundant.

Could you explain WHY you need this field? What purpose does it serve,
and what are you going to do with it? I *VERY* strongly suspect that
your business need can be easily met *without* storing this
abomination in the table.

John W. Vinson[MVP]
 
G

Guest

Hi,
I have to agree with John.
There is NO reason to store this field value in a table. It is redundant and
duplicated and breaks normalization rules. Since you already have both parts
of the value you can combine them at runtime on forms or reports as you are
trying to do. That's all you should be doing with it.
HTH
Good luck
 
F

FA

Well John i the field name is Finding No and Finding No is compose of
AppCode and TestBeginDate. Its a unique number that my company has
standardized in such form. I have Finding table in my sql server db
were its datatype is varchar (20) so i think it should take any string.
that is the only reason why i need to populate this field with these
two other fields. AppCode and TestBeginDate aare on a different form
calld frmSystem and i am taking the data of these two fields linking it
to frmNewFidindg and trying to populate these two all together in one
field called Finding No. AppCode is Alphabetics and TestBeginDate is
data but when they go together in FindingNo it should be as Varchar.
I hope you would understand my problem

Thanks millions

Moe
 
F

FA

I think i am going to need a VBA function that takes two values


Dim Val1 As String
Dim Val2 As Date
Dim Val3 As String


Combine Val1Val2 and return a single value Val3 As String


With Val3 Add 001 for the first record 002 for the second record and so

on


insert Val3001 into a texbox


So for Example if Val1 = ABCDE, Val2 = 01/01/2006
Val3 shoule be = ABCDE01/01/2006001 --- for the first record (or for
the first time)

If anyone can help me writing the code for this funtion, i would really
apreciate it.

Thanks
Moe
 
F

FA

I have created the following funtion and but its not working,

Public Function CalculateFindingNo(Val1 As String, Val2 As Date) As
String
CalculateFindingNo = Val1 & Val2
End Function

I have txtbox1 (providing Val1) , txtbox2 (providing Val3) and txtbox3
showing the result of the function.

I am calling in the AfterUpdateEvent of txtbox2
Me.txtbox3 = CalculateFindingNo(Me.txtbox1, Me.txtBox2)

Its not working folks

Pleae help

Moe
 
D

Douglas J Steele

What does "not working" mean?

Do you get an error? If so, what is it? If you don't get an error, are you
getting some value, just not the value you're expecting? If you are getting
some value, how does it differ from what you're expecting?
 
J

John Vinson

Well John i the field name is Finding No and Finding No is compose of
AppCode and TestBeginDate. Its a unique number that my company has
standardized in such form. I have Finding table in my sql server db
were its datatype is varchar (20) so i think it should take any string.
that is the only reason why i need to populate this field with these
two other fields. AppCode and TestBeginDate aare on a different form
calld frmSystem and i am taking the data of these two fields linking it
to frmNewFidindg and trying to populate these two all together in one
field called Finding No. AppCode is Alphabetics and TestBeginDate is
data but when they go together in FindingNo it should be as Varchar.
I hope you would understand my problem

Thanks millions

Moe

It sounds like your SQL/Server database is what is incorrectly
structured. Knowing corporate IT departments, I'm going to just
surrender and help you do it wrong.

You need just a few lines of VBA, and you do not need any custom
function.

In the AfterUpdate event of both AppCode and TestBeginDate, put code
like this:

Private Sub AppCode_AfterUpdate()
If Not IsNull(Me!AppCode) And Not IsNull(Me!TestBeginDate) Then
Me![FindingNo) = Me!AppCode & Format(Me!TestBeginDate,"mm/dd/yyyy")
End If
End Sub

John W. Vinson[MVP]
 

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