Null errors in simple database, why?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 20
Reputation: Entropy1024 is an unknown quantity at this point 
Solved Threads: 0
Entropy1024 Entropy1024 is offline Offline
Newbie Poster

Null errors in simple database, why?

 
0
  #1
Oct 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 45
Reputation: AUGXIS is an unknown quantity at this point 
Solved Threads: 11
AUGXIS's Avatar
AUGXIS AUGXIS is offline Offline
Light Poster

Re: Null errors in simple database, why?

 
0
  #2
Oct 13th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,104
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Null errors in simple database, why?

 
0
  #3
Oct 14th, 2008
you need to update the third field by concatinating field1 and field2
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Null errors in simple database, why?

 
0
  #4
Oct 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: hell_tej is an unknown quantity at this point 
Solved Threads: 2
hell_tej hell_tej is offline Offline
Junior Poster in Training

Re: Null errors in simple database, why?

 
0
  #5
Oct 15th, 2008
Just Try this i think it's works



Data1.Recordset.Fileds(“ResultString”) = Data1.Recordset.Fileds(“String1”) & "" + Data1.Recordset.Fileds(“String2”) & ""
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Null errors in simple database, why?

 
0
  #6
Oct 16th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,104
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 128
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: Null errors in simple database, why?

 
0
  #7
Oct 16th, 2008
then why not insert the third field also by concatinating the 1st and the 2nd value . still you have to enter 2 values only.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 20
Reputation: rstkw is an unknown quantity at this point 
Solved Threads: 2
rstkw rstkw is offline Offline
Newbie Poster

Re: Null errors in simple database, why?

 
0
  #8
Oct 25th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC