If I create a database that has 3 fileds per record; String1, String2 & ResultString. I want the user to enter in the first 2 strings then the program creates ‘ResultString’ by adding the String2 to String 1 itself.
Ie if you enter Big as String1 and Cat as String2 I want ResultString to be BigCat.
I guess I create a sub that is triggered by a change in either 1 of the 2 user entered fields then execute some code as below:

Data1.Recordset.Fileds(“ResultString”) = Data1.Recordset.Fileds(“String1”) + Data1.Recordset.Fileds(“String2”)

But I get a Null error. What am I doing wrong?
Many thanks for any help.

hi. i think it is much better that you will use the values of the string1 and string2 for the value of Data1.Recordset.Fileds(“ResultString”). You have not yet save any the data so your values for Data1.Recordset.Fileds(“String1”) and Data1.Recordset.Fileds(“String2”) are both null.

Data1.Recordset.Fileds(“ResultString”) = string1 + String2
Data1.Recordset.Fileds(“ResultString”) = Data1.Recordset.Fileds(“String1”) + Data1.Recordset.Fileds(“String2”)

AUGXIS is correct. If youre trying to save the records in the database use the existing data...

With Data1.Recordset
       .Addnew
       .Fields("String1") = "Big"
       .Fields("String2") = "Cat"
       .Fields("ResultString") = "Big" & "Cat"
       .Update
End With

or...

With Data1.Recordset
       .Addnew
       !String1 = "Big"
       !String2 = "Cat"
       !ResultString = "Big" & "Cat"
       .Update
End With

Just Try this i think it's works


:) Data1.Recordset.Fileds(“ResultString”) = Data1.Recordset.Fileds(“String1”) & "" + Data1.Recordset.Fileds(“String2”) & ""

hell_tej it cant be... null value will be returned from

Data1.Recordset.Fileds(“String1”) & "" + Data1.Recordset.Fileds(“String2”) & ""

because it's a new record and not yet inserted/saved in the database.

then why not insert the third field also by concatinating the 1st and the 2nd value . still you have to enter 2 values only.

There's another problem you can run into that will give a Null error. If one field is empty there is nothing to concatenate. So how do you check for that? If you read the textbox into a text variable and check for Null, it will never be Null because it is a string type. IsNull only works with variants, I think. So assign the .text from the textbox to a variant and use IsNull. If the .text is not Null, you can use it as-is, or re-assign it to a string variable. If it IsNull, replace it with "" and go on.

This article has been dead for over six months. Start a new discussion instead.