Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    refresh? (Xp,2000)

    I have some textbox controls that contain the following:

    =" Record " & [CurrentRecord] & " of " & RecordSet.RecordCount

    What I want is to have the textbox say "Record X of Y" . It works but it seems that when the form first loads, it will say 1 of 1 then 2 of Y, and so on. In other words, it doesn't seem to know the recordcount initially, only after I move to the next record does it update. Would it be good to have me.refresh as an on current event? Would that help?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: refresh? (Xp,2000)

    If you set the NavigationButtons property of the form to Yes, Access will display the correct values automatically. If you don't want to use the built-in navigation buttons, you have to force Access to get the number of records by moving to the last record when the form is opened. You can do this in the On Load event of the form:

    Private Sub Form_Load()
    RunCommand acCmdRecordsGoToLast
    RunCommand acCmdRecordsGoToFirst
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: refresh? (Xp,2000)

    Thank you. This works perfectly and, yes, I am using my own navigational controls. However, this brings up two questions...

    1) I notice that I am typing a lot of the same code into many control events. Is there a way to define a sub once then call it repeatedly so I don't have to type the same code repeatedly? If so, Where would I place it?

    2) What is the diffeence between on current and on load? When would I use one vs. the other?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: refresh? (Xp,2000)

    1) For use within a form module, you can put code used repeatedly into a separate procedure, and call it from several event procedures:

    Private Sub CommonCode()
    ...
    ...
    End Sub

    Private Sub Form_Load()
    CommonCode
    End Sub

    Private Sub ...
    CommonCode
    End Sub

    If you have code you want to reuse in several forms, you have to be careful, since a reference to Me is only valid in the module belonging to the form, you can't use it in a standard module. You can use CodeContextObject instead. For example, CodeContextObject.Name will return the name of the form from which the code is called, even if the code itself is in a standard module.

    2) On Load occurs when the form is loaded into memory. It occurs once, when you open the form. On Current occurs when you move to another record. It occurs at least once when you open the form, but also each time you move to the next record etc. So you would use On Load when you want to initialize something when the form is opened. and On Current if you want to set something each time you move to another record

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •