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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

absolutePosition value

Status
Not open for further replies.

aggeliki23

Programmer
Feb 12, 2007
38
GR
hello i am new here and i need your help
i am a new programmer and i programming in visual basic

i declare an adodb recordset in my code like this
dim rs as adodb.recordset

in form load:
i open the connection, i open the sql query with the rs object
Set rs = New ADODB.Recordset
rs.Open sql, conn, adOpenStatic, adLockOptimistic

i set the data source in textboxes and datafields with the names of the fields of the table i use in sql query to appear the records in them
and then i call rs.movefirst
when i appear the rs.absoluteposition with statement msgbox rs.absoluteposition i see that the value is =-1.
Why does it happens? Why value of rs.absolutePosition is -1?
I think that the -1 value is if the current record is bof
I tried this
if rs.bof=false then
msgbox rs.absoluteposition
end if
but i am still getting -1 value. I have confused, i don't know the value that must have rs.absoluteposition, is 0 or 1? And what can i do having my rs.absolutePosition the properly value? May anyone help please?
 
Try the help file:
Settings and Return Values

The setting or return value is a Long integer from 0 to one less than the number of records in the Recordset object. It corresponds to the ordinal position of the current record in the Recordset object specified by the object.

Remarks

You can use the AbsolutePosition property to position the current record pointer to a specific record based on its ordinal position in a dynaset- or snapshot-type Recordset object. You can also determine the current record number by checking the AbsolutePosition property setting.

Because the AbsolutePosition property value is zero-based (that is, a setting of 0 refers to the first record in the Recordset object), you cannot set it to a value greater than or equal to the number of populated records; doing so causes a trappable error. You can determine the number of populated records in the Recordset object by checking the RecordCount property setting. The maximum allowable setting for the AbsolutePosition property is the value of the RecordCount property minus 1.

If there is no current record, as when there are no records in the Recordset object, AbsolutePosition returns –1. If the current record is deleted, the AbsolutePosition property value isn't defined, and a trappable error occurs if it's referenced. New records are added to the end of the sequence.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thank you very much. Your really helped me.
I improved my code and i made all the checkings properly!
Also i add the statement rs.CursorLocation = adUseClient before open my sql query with the rs object and i noticed
that when the form loads and the first record of my table appeares the absoluteposition was 1. Is this properly or not? Because you told me that the setting or return value is a Long integer from 0. Although if i say rs.CursorLocation = adUseServer when the form loads the value of absolutePosition is -1 and it behaves like this you told me "If there is no current record, as when there are no records in the Recordset object, AbsolutePosition returns –1. If the current record is deleted, the AbsolutePosition property value isn't defined, and a trappable error occurs if it's referenced. New records are added to the end of the sequence."
With the rs.CursorLocation = adUseClient looks like working fine it appears all the records when i click nextbutton and its not adding new records to the end of the sequence. But I don't know if its really correct because the absolute position value starts from 1.
Here is the next button code:
Private Sub next_Click()
If rs.AbsolutePosition < rs.RecordCount Then
rs.MoveNext
MsgBox rs.AbsolutePosition
End If
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top