Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question Unanswered: Determine if you're on a New Record in a form

    On the form's OnCurrent event, I want to do a test see if the record is a new one (for example the autonumber field would not have a value yet, until the user starts editing), or if the user just scrolled onto an existing record.

    Is this a proper check to do?:
    If Not Me.NewRecord = True Then .... ?

    Any scenarios where it is not sufficient, or where some other possible checks can/should be done?

    Out of curiosity, I would anyway like to know what "value" a autonumber text field has on a new record just before editing it. (something it is possible to run tests on, if not the above or other method should handle all possible scenarios)

    Thanks.

    D.

  2. #2
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250
    Maybe. It has to do with the record pointers and/or the Last record. If you create a query that returns no results and look at the navigation buttons you will see the only enabled buttons are the move first and move last buttons (they have an arrow & vertical line). It also shows the "first" record, but until you add data [and update it-- in VBA recordsets] its not a record. There are to pointers called BOF and EOF for beginning/end of file. If either of these is true then there is no current record.

    From help, "The Current event occurs when the focus moves to a record, making it the current record, or when the form is refreshed or requeried." So by this definition, "to do a test see if the record is a new one" doesn't seem necessary.

    Lastly, "Out of curiosity, I would anyway like to know what "value" a autonumber text field has on a new record just before editing it. " If you need it in VBA it would be tablename(0) for the first field as your autonumber.

    HTH

  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by poliarci
    Lastly, "Out of curiosity, I would anyway like to know what "value" a autonumber text field has on a new record just before editing it. " If you need it in VBA it would be tablename(0) for the first field as your autonumber.
    HTH
    ok, I know the BOF and record selecting stuff, my questions are these:

    1. Is it the Me.NewRecord that is the best general test?

    2. Out of curiosity: If I just want to know the technical value to test for when a text box based on a autonumber field is in this state:
    Say I have a autonumber field that is normally filled with a numeric value. However, whenever the state of the form is a new record that has not entered edit/dirty state yet, all that shows in the text box is (Autonumber) at that moment. How can one programatically in VBA determine whenever this is the state of the form/record? What value is technicallyin that text box when it shows "(Autonumber)"? I assume it cannot be the visible text as the underlying field is numeric?

    Daniel.

  4. #4
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250
    Originally posted by kedaniel
    1. Is it the Me.NewRecord that is the best general test?
    You can use the NewRecord property to determine whether the current record is a new record.

    Originally posted by kedaniel
    2. Out of curiosity: If I just want to know the technical value to test for when a text box; ... all that shows in the text box is (Autonumber) at that moment. How can one programatically in VBA determine whenever this is the state of the form/record? What value is technicallyin that text box when it shows "(Autonumber)"? I assume it cannot be the visible text as the underlying field is numeric?

    Daniel.
    In VB code the rst.AddNew would be the equivelent of the "dirty" state you describe. When you do an rst.Update it committs the data entered into the fields. With Autonumber any field needs a non-null value to get the value of auto number. Can/did you force a dummy variable with a value and check the autonumber value?

Posting Permissions

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