Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    178

    Unanswered: null problem on variables.. need some insight please

    Hi Guys,

    ok here is a situation. I have some information on a form, i want to duplicate this info on another record.

    so i created some variables copied the info of the record into those variables then created a new record and copied the data back from the variables into the bound txt boxes.

    what i found was with one particular variable i kept getting an error stating null value something. the field that i copied didnt contain anything, but i had several like that which didnt cause any errors.

    How i got around it was to add another variable that does nothing to the list of the ones i created ie.

    When i had the problem:

    Dim tmpName, tmpLName, tmpAddress as String

    I had a problem with tmpAddress, then all i did was add tmpAddress2 to the list of variables

    When the problem disappeared ie:

    Dim tmpName, tmpLName, tmpAddress, tmpAddress2 as String


    the tmpAddress2 is vacant, doenst do any thing, im trying to understand why this happens?

    Thanks

    Aboo

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    A string variable can not handle a Null; only a Variant can. When you have this:

    Dim tmpName, tmpLName, tmpAddress as String

    You are actually declaring 2 Variants and 1 String. The correct syntax for 3 Strings would be:

    Dim tmpName as String, tmpLName as String, tmpAddress as String

    Obviously, you don't want strings anyway, so I'd do this:

    Dim tmpName as Variant, tmpLName as Variant, tmpAddress as Variant

    While you can leave off the "as Variant" and get Variants anyway, I prefer to explicitly declare them.
    Paul

  3. #3
    Join Date
    May 2006
    Posts
    178
    thanks Pbaldy!

    just what i needed!

    regards

    Aboo

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by aboo
    Hi Guys,

    ok here is a situation. I have some information on a form, i want to duplicate this info on another record.

    so i created some variables copied the info of the record into those variables then created a new record and copied the data back from the variables into the bound txt boxes.

    what i found was with one particular variable i kept getting an error stating null value something. the field that i copied didnt contain anything, but i had several like that which didnt cause any errors.

    How i got around it was to add another variable that does nothing to the list of the ones i created ie.

    When i had the problem:

    Dim tmpName, tmpLName, tmpAddress as String

    I had a problem with tmpAddress, then all i did was add tmpAddress2 to the list of variables

    When the problem disappeared ie:

    Dim tmpName, tmpLName, tmpAddress, tmpAddress2 as String


    the tmpAddress2 is vacant, doenst do any thing, im trying to understand why this happens?

    Thanks

    Aboo
    i'm starting to get a leetle scared by what you are doing on behalf of your employer

    copying data suggests to me that there is a risk of duplicating data..somehting you should virtually never ever do. if you are doing that usually its a symptom of suspect design.

    Dim tmpName, tmpLName, tmpAddress, tmpAddress2 as String
    does not do what you think it is doing
    thats declaring 3 varaibles as variants, and one as string
    to declare each as string you need to do that as
    Dim tmpName as String
    dim tmpLName as String
    dim tmpAddress as String
    dim tmpAddress2 as String
    Last edited by healdem; 05-08-09 at 03:18.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    A little late on that trigger?
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •