Can Someone Explain This Line of Code?

10-27-2004, 03: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?


10-27-2004, 04:00 PM

lblhorsepower = "" & rsAdressBook!Horsepower

rsAdressBook is the recordset
Horsepower -its field


10-27-2004, 04: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?

10-27-2004, 06: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.

10-27-2004, 10: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

10-28-2004, 03: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)

11-05-2004, 09: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