943,775 Members | Top Members by Rank

Ad:
Oct 13th, 2008
0

Null errors in simple database, why?

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Entropy1024 is offline Offline
20 posts
since Oct 2008
Oct 13th, 2008
0

Re: Null errors in simple database, why?

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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Data1.Recordset.Fileds(“ResultString”) = string1 + String2
Reputation Points: 11
Solved Threads: 11
Light Poster
AUGXIS is offline Offline
45 posts
since Dec 2007
Oct 14th, 2008
0

Re: Null errors in simple database, why?

you need to update the third field by concatinating field1 and field2
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Oct 14th, 2008
0

Re: Null errors in simple database, why?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With Data1.Recordset
  2. .Addnew
  3. .Fields("String1") = "Big"
  4. .Fields("String2") = "Cat"
  5. .Fields("ResultString") = "Big" & "Cat"
  6. .Update
  7. End With
  8.  
  9. or...
  10.  
  11. With Data1.Recordset
  12. .Addnew
  13. !String1 = "Big"
  14. !String2 = "Cat"
  15. !ResultString = "Big" & "Cat"
  16. .Update
  17. End With
Last edited by jireh; Oct 14th, 2008 at 9:14 am.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Oct 15th, 2008
0

Re: Null errors in simple database, why?

Just Try this i think it's works



Data1.Recordset.Fileds(“ResultString”) = Data1.Recordset.Fileds(“String1”) & "" + Data1.Recordset.Fileds(“String2”) & ""
Reputation Points: 15
Solved Threads: 3
Junior Poster in Training
hell_tej is offline Offline
53 posts
since Apr 2008
Oct 16th, 2008
0

Re: Null errors in simple database, why?

hell_tej it cant be... null value will be returned from
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Data1.Recordset.Fileds(“String1”) & "" + Data1.Recordset.Fileds(“String2”) & ""
because it's a new record and not yet inserted/saved in the database.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Oct 16th, 2008
0

Re: Null errors in simple database, why?

then why not insert the third field also by concatinating the 1st and the 2nd value . still you have to enter 2 values only.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Oct 25th, 2008
0

Re: Null errors in simple database, why?

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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
rstkw is offline Offline
20 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: String Handling
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Splitting up Strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC