Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Location
    Frankfurt, Germany
    Posts
    20

    Unhappy Unanswered: Modifying data in forms by code

    hi folks,

    does anybody know, how i can modify data in the current record set of a form by vb code BEFORE the user has started editing any of the form fields?

    because in this case usually the form or record set is not in editing mode and the trial to modify a field value or form field value by code will either result in an error message or even in a crash of the whole access application ("MS Access has encountered a problem...", you know the ...)

    in other words: is there a way of switching a record to editing mode before the user has done any action in the form?

    thank you very much,

    ron

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Are you saying that you want to test each record as it comes up to decide whether to allow the user to edit? If so, put the following code
    in the forms OnCurrent property:

    Dim bolTest as boolean
    ...
    'perform your testing, using the boltest
    'as a true/false flag for turning edit mode on/off

    ....
    Me.AllowEdits=bolTest

  3. #3
    Join Date
    Jul 2003
    Location
    Frankfurt, Germany
    Posts
    20
    to be more presize:
    sql server 2000 backend
    adp project
    datasource of the form is the table, not a stored procedure

    letīs say the user only views a record in my form, does NO editing at all

    now before leaving the record i want to save the current date and time in a column of this record called "LastViewed":
    the code

    me!LastViewed = now

    will lead to an error or even access application crash
    and i donīt know why.
    i guess itīs because the user hasnīt edited the record at all and the form is NOT in sort of an editing mode, but how can i move into this mode?

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    If you have the Allow Edits property for the form set to No, and you want
    to change some of the data in the form, then you have to change it to
    edit mode through VBA:

    me.allowedits=true
    me!LastViewed = now
    me.allowedits=false

    This should probably be in the form's OnCurrent event, that way it will
    be done as soon as the user moves into a record.

  5. #5
    Join Date
    Jul 2003
    Location
    Frankfurt, Germany
    Posts
    20

    Wink

    nope
    allowedits is set to true already by design

    next try please ;-)

    ps:
    come on, the obvious things i have already checked myself ;-)

  6. #6
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Ron,
    I guess I misunderstood your original question. I have an uncanny
    knack for stating the obvious!

    Are you saying that you want your code to take one action if the user
    views a record, but does not edit it; and a different action if the user
    edits the form?

    Since Access doesn't have a OnLeaveRecord event (kinda like the opposite of OnCurrent) I build my own buttons to move through the
    recordset, and turn off the navigation buttons. That way I can do things
    like:

    If Me.Dirty then
    ...
    or

    If Me.Newrecord then
    ...

    That allows you to test what the user entered, or make changes to data,
    before moving on to the next record.

  7. #7
    Join Date
    Jul 2003
    Location
    Frankfurt, Germany
    Posts
    20

    Smile

    >>Are you saying that you want your code to take one action if the user
    views a record, but does not edit it; and a different action if the user
    edits the form?<<

    well, i am saying:
    i want to take action in any case, even if the user does not do anything.

    but you have already brought my nose to the right trail i guess:
    i never cared about the property "dirty" and itīs purpose.
    maybe i havenīt tried ALL the obvious things so far... ;-)

    thanx,
    keep hackinī

    regards,
    ron

Posting Permissions

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