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

Adding Record Number as Caption in Data Control

Status
Not open for further replies.

Eytch

Programmer
Jan 29, 2003
60
US
I would like to get the Caption of the Data Control to illustrate the record number of the current record from the table and database being accessed. However, many of the commands associated with either VB or Access are not compatible with one another. For example, neither "AbsolutePosition" nor "CurrentRecord" work here.
I would like this line of code "DatItemPrice.Caption = "Record" to have the record number appended to it.

Thanks,
Tripoli


Option Explicit
Public gdbCurrent As Database
Private mrstCurrent As Recordset

Private Sub Form_Load()
Unload frmEx2
Set gdbCurrent = OpenDatabase("A:\Chapter.08\Exercise\Steel.mdb")
Set mrstCurrent = gdbCurrent.OpenRecordset("tblPriceList")
'Dim lngrecordnum As Long

'lngrecordnum = mrstCurrent.AbsolutePosition

DatItemPrice.Caption = "Record" & lngrecordnum

The last line of code doesn't work - any suggestions?


End Sub
 
Every time I load data into a label or caption I put a DoEvents after the command and it works. Swi
 
Hi Swi,

As I am not familiar with the DoEvent could you direct me to an example of how I would apply it to my predicament.

Thanks,
Tripoli
 
Doevents enables background events to be processed.

Try this:
DatItemPrice.Caption = "Record" & lngrecordnum
DoEvents

' Rest of code here Swi
 
Also your above code is commented out.


'Dim lngrecordnum As Long

'lngrecordnum = mrstCurrent.AbsolutePosition

DatItemPrice.Caption = "Record" & lngrecordnum Swi
 
Swi,

The DoEvents command does not work.

I get a Run-time error '3251':
Operation is not supported for this type of object.

I have tried almost every Method/Property available and can't get the record number to appear in the caption.

Thanks,
Tripoli
 
AbsolutePosition only works with dynasets or snapshots and it is also zero based. Try something like this:


Option Explicit
Public gdbCurrent As Database
Private mrstCurrent As Recordset

Private Sub Form_Load()
Unload frmEx2
Set gdbCurrent = OpenDatabase("A:\Chapter.08\Exercise\Steel.mdb")
Set mrstCurrent = gdbCurrent.OpenRecordset("tblPriceList", dbOpenSnapshot)
Dim lngrecordnum As Long
lngrecordnum = mrstCurrent.AbsolutePosition + 1
DatItemPrice.Caption.Caption = "Record: " & lngrecordnum

End Sub Swi
 
Swi,

I gave your latest suggestion a try. It results in "Record: 1" as the caption but does not increment when any of the buttons in the Data control are clicked. "Record: 1" appears as the caption for all records. Any ideas?

Thanks again for your help.
Tripoli
 
You must put the code for changing the label caption in the appropriate event where you are navigating the records.... probably the click event of the Next / Previous button
 
infinito,Swi,

I am trying to get this to work in a Data Control. I found the following reference at the site given below. I tried Swi's suggestion within the Reposition Event but can't get it to go. Any ideas?

Data1.RecordSet.AbsolutePosition
The number of the current record in the RecordSet. Starts at zero. This property does not appear to be reliable in VB6. I put code to display this in the Data Control's Reposition event, and sometimes it worked, sometimes it gave odd results


Thanks,
Tripoli
 
This worked for me:

Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Form1.Caption = "Record " & Adodc1.Recordset.AbsolutePosition & " of " & Adodc1.Recordset.RecordCount
End Sub

Private Sub Form_Load()
Form1.Caption = "Record " & Adodc1.Recordset.AbsolutePosition & " of " & Adodc1.Recordset.RecordCount
End Sub Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top