Can Someone Explain This Line of Code?

paidelr
10-27-2004, 04:45 PM
lblhorsepower = rsAdressBook!Horsepower


This is in the list1_click function. I know that lblhorsepower is a label. What is rsAdressBook!Horsepower.

My interpretation was that 'AdressBook' is my database name and Horsepower is a column in the database but I'm just confusing myself?

When I run the program, I get an 'Invalid Use of Null' error on the above line of code, obviously because VB can't read rsAdressBook!Horsepower .

So for now, can someone just explain each part of the above code. Does 'rs' for with AdressBook or are they two different things. What is the '!' for?

Thanks.

Shurik12
10-27-2004, 05:00 PM
Try,

lblhorsepower = "" & rsAdressBook!Horsepower

rsAdressBook is the recordset
Horsepower -its field

Shurik.

paidelr
10-27-2004, 05:15 PM
Thank-you. A lot of the code I have makes a lot of sense now. :)

Just another question.

lblName = rsAdressBook!Name

this doesn't have or need a "" &. Why would that be?

loquin
10-27-2004, 07:08 PM
The "" was used to correct for a possible null value in the field. You should probably add this to any line that references a recordset field where the field value could be null.

tasya
10-27-2004, 11:26 PM
or you can use this

lblName = iif(isnull(rsAdressBook!Name),"",rsAdressBook!Name)

that statement is also to check if rsAdressBook!Name null or not

NEOLLE
10-28-2004, 04:25 AM
Like what tasya said, you can use the IIF Statement.
Im not sure if there is a significanT difference, but I use the Empty function rather than "".

lblName = iif(isnull(rsAdressBook!Name),Empty,rsAdressBook!Name)

loquin
11-05-2004, 10:16 AM
However, (good to know if your code is within a loop,) the IIF function is much less efficient than simply using the If-Then-Else code construct.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum