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!

How to read current record # on a form

Status
Not open for further replies.

ReWeFe

MIS
Mar 30, 2003
25
US
Hello there,

as a part of a little VBA module on form, I need to be able to somehow read/get/return the current record number, the same record number which data is shown on the form, and put it in a variable.

Any advice is highly appreciated.

Thanks.
 
Hi,

There was a similar code in here. Anyway i adapted that into mine. Hope this can help.

in the OnCurrent event
Me.RecordsetClone.Bookmark = Me.Bookmark
CurrRec.Value = Me.RecordsetClone.AbsolutePosition + 1
'to get current record no
AllRec.Value = Me.Recordset.Clone.RecordCount
'to get last record no

To ensure that the current record is displayed once the page is opened.

in the OnLoad event
DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acFirst
'to ensure that the record no is updated

 
To only get the current record number you can use

Dim CurrRecNo As Long
CurrRecNo=Me.CurrentRecord

You can use it in almost any event you like.
 
Thanks a bunch JasperBond :)

Nice and simple!

Just gave you some kudos.

I'll give you more if you can solve this too:

I have a form, same as above, where I have two check boxes, that tell if a face and/or a full picture (standard named) is available for a person. If it is I try and show the picture in an unbound box, but I get two different errors, on different occasions.


Error #1

"Microsoft Visual Basic
Run-time error '2753'
A problem occured while Microsoft Access was communicating with the OLE server or ActiveX Control"

I keep getting this error, even when I click my command button, see code below.

Private Sub Form_Current()
UpdatePictures
End Sub

Public Sub UpdatePictures()
bitFullPicture_Name_Click
bitFacialPicture_Name_Click
End Sub

Private Sub bitFacialPicture_Name_Click()
  If bitFacialPicture = True Then
    oleFacialPicture.SourceDoc = "C:\Face\PopularName.jpg"
    oleFacialPicture.Action = acOLECreateLink
  Else
    oleFacialPicture = Null
  End If
End Sub

Private Sub bitFullPicture_Name_Click()
  If bitFullPicture = True Then
    oleFullPicture.SourceDoc = "C:\Full\PopularName.jpg"
    oleFullPicture.Action = acOLECreateLink
  Else
    oleFullPicture = Null
  End If
End Sub"

The variable "bitFacialPicture" and "bitFullPicture" is a Yes/No field/checkbox. The filename is actually generated from a name field on the form. When checked the picture is supposed to be shown and I use the "oleFacialPicture = Null" if it's not set, to erase the picture from the unbound field as it does not clear by it self.

Error #2 I'm getting, sometimes it works for a while and then if I click my above posted command button with code twice on the same record I get this error:

"Run-time error '2719':
A problem occured while accessing the OLE object"


Hope you or anyone else can help.

Thanks.
 
Hi,
Thanks .), and glad it helped.

I have never used OLE objects, so i am lost there. Hope someone else can jump in.

Good luck

jasper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top