Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions on recordset 2

Status
Not open for further replies.

chrislx

Programmer
Oct 17, 2003
32
US
Please help me on the followings:

What is the difference from
1). Dim rs as Object
And 2). Dim rs as DAO.Recordset ?

When either one should be used?
rs = Me.Recordset.Clone
rs = Me.RecordsetClone

What is the difference from the followings and when one should be used?
1). rs![Part-Id]
2). rs("[Part-Id]")

Thanks in advance,

ChrisLx
 
dim rs as object, is what's referred to as "late binding". It means that Access doesn't know what kind of object it is before at runtime. For you as a programmer, it also means the intellisense isn't working;-) Early binding is faster than late binding, but are used, for instance if one anticipates "challenges" with the libraries.

Me.Recordset.Clone is using the clone method of the recordset, and Me.RecordsetClone is the clone of the recordset. I believe in ADP's/ADO you might have to use the .clone method, but I'm not sure. When dealing with the ordinary form recordsets (mdb's) I always use the recordsetclone.

Both reference types are valid, and can be used anytime you like. The advantage of the latter, is that you can pass variables to it/use it to provide the access equivalent of controls array:

[tt]dim sControl as string
dim i as long
sControlName = "txtMyText"
for i = 1 to 10
Debug.print Me(sControlName & i).Value
next i[/tt]

Roy-Vidar
 
When you declare a variable as an object then VB has to figure out what kind of object it is before executing any code based on this variable. Declaring the variable as DAO.recordset will tell VB explicitly what the variable is so it does not have to determine the object type later. Look up late binding and early binding on the net to get more info.

As to your second question check out this link:


HTH,
Eric
 
Hmpf - to focused on form controls...

let's rephrase to make it possible to reference also fields more dynamicly, perhaps like this:

[tt]dim i as long
for i = 0 to rs.fields.count-1
Debug.print rs.fields(i).Name, rs.fields(i).Value
next i[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top