Results 1 to 13 of 13
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Write Confilct (XP 2000)

    1. I wouldn't do this in the On Change event of each control, but in the Before Update event of the form.

    2. It is not clear to me which tables are involved, but can't you just set the date field in the Before Update event, instead of running a query:

    Me.DateField = Date

  2. #2
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    The form is a continous form, so there are many records displayed. I only want to update the date for a record that is changed, not all records on the form.

    I also only want the date updated IF the records is changed...

    I dont completely understand the Before Update and AfterUpdate methods.

    Basically i have a table with fields, DOC ID, TITLE, NOTES, DATE LAST EDITED

    i have a form for just viewing these records, and then another form (the same with different properties) for editing them.
    Thanks,

    pmatz

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

    Re: Write Confilct (XP 2000)

    Both the Before Update and After Update event of a form occur when the user moves away from a record, by moving to another record, or by closing the form, AND if the current record has been modified. Both events don't occur when the user moves away from a record that has not been modified. The main difference between the events is that BeforeUpdate has an argument Cancel that can be set to True if you want to cancel the update. In that case, the record will not be saved. If you want to modify a value, you must use the Before Update event, for if you use the After Update event, you'll create an endless loop.

    In a continuous form, only one record is current, even if many records are displayed. Setting a value in the Before Update event of the form will only affect the current record. So try this code in the Before Update event of the form used to edit records:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.[DATE LAST EDITED] = Date
    End Sub

    You don't need this code in the form used to view records - since a record can't be modified there, the Before Update event will never fire.

  4. #4
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    AH, THANKS FOR THE SIMPLE IDEA of Me.Date = Date

    i added the lastedited field to the form, but set the visible to false, then used me.lastedited = now() on the change events.,

    this seems to work, keeping the records updated and specific to whichever record is changed on the continous form

    cool
    Thanks,

    pmatz

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

    Re: Write Confilct (XP 2000)

    That will work too, but setting the last edited date in the on change event of each editable control generates a lot of overhead: the date will be set on each keystroke. Setting it once in the Before Update event of the form has the same effect in the end, and is much more efficient.

  6. #6
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    Ok, i will try that, but will it only update the record that i edit if i set it for the beoreupdate method of the form?

    or should i use the beforeupdate method of the fields?

    another (random) question...

    how do i get a form to load and then wait for a specific (secret) keypress before either setting focus to the first field, or closing...

    i have been looking at soing keypress = true on the form load...
    Thanks,

    pmatz

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

    Re: Write Confilct (XP 2000)

    1. As I already wrote in a previous reply, Before Update only affects the current record (and only if it has been modified), even if many records are displayed in a continuous form.

    2. I don't understand your other question. A form always sets the focus to the first enabled control in the tab order. What do you want to accomplish?

  8. #8
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    Thanks Hans, I missed your previous thread with a very good explanation of the before and after update events. THANKS. sorry to confuse you!

    Well, yes, this works fine now.

    what i was trying to achieve with the form keypress events is the following...

    for a form to open and then 'wait for a keypress'... if a (secret) key is pressed then a certain action to occur, else go on as normal.
    FOrgive me if this is annoyingly nonpractical !

    3. Why is it that the pagedown key annoyingly always clears the current record when you are in a add data mode in a form.?

    i open my form DataAdd, and a nice new record is displayed, but when i press pagedown ( say a user may do this by accident) the record moves on and problems with primary keys occurr. I have found a way around this by using error handling and setting back to first record, but is there a way of diasabling this?

    hope its ok racking your brain today man...

    kind regards
    Thanks,

    pmatz

  9. #9
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write Conflict (XP 2000)

    Hi, i am getting a write conflict error when i am updating records, giving me options to either Save Record or Drop changes.

    I have a form I am using to edit records that opens based on a query from a main table.

    On each of the enabled fields I have a Change Event driven code which in turn runs a Query.

    This Query looks up the records from an ID field within the form and then updates another field in the to todays date.

    I thought this was a good way of making sure the 'Last Edited' field in my table was always up to date.

    However when i close the form i get this message, and depending on whether i choose 'Save Record' or 'Drop Changes' I get different results!

    If i save the record then the changes stay, but somehow the updated field from the query is not kept.

    If i drop changes then the changes to the record are dropped, but the updated field from the query is kept!!!

    I want both these, to keep changes, but also for the query to work...

    Am I just complicating matters - is there an easy solution?

    [img]/forums/images/smilies/smile.gif[/img] thanx
    Thanks,

    pmatz

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

    Re: Write Confilct (XP 2000)

    2. To detect a special keystroke:

    - Set the Key Preview property of the form to Yes (in the Event tab of the Properties window.) This means that all keyboard events will be passed to the form first, and only then to the control in which the keyboard event actually occurs.
    - Use the On Key Down (or On Key Up) event of the form. You can check the status of the Ctrl, Alt and Shift keys in this event. Say that your secret key is Ctrl+Alt+G, and the special action is to sound a beep, you could use this code:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim CtrlDown As Boolean
    Dim AltDown As Boolean
    ' Test modifier keys
    CtrlDown = Shift And acCtrlMask
    AltDown = Shift And acAltMask
    ' Did user press Ctrl+Alt+G?
    If KeyCode = vbKeyG And CtrlDown And AltDown Then
    ' Your special action here
    Beep
    ' Prevent key from being handler further
    KeyCode = 0
    End If
    End Sub

    3. PageDown moves the next record (i.e. a new one if you are on the last record), PageUp to the previous record. You can nullify these keys in the On Key Down event of the form too, by testing if KeyCode is vbKeyPageDown or vbKeyPageUp, and setting KeyCode to 0 if that is the case. You can combine this with the above code, or use a Select Case statement:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim CtrlDown As Boolean
    Dim AltDown As Boolean
    Select Case KeyCode
    Case vbKeyG
    ' Test modifier keys
    CtrlDown = Shift And acCtrlMask
    AltDown = Shift And acAltMask
    ' Did user press Ctrl+Alt+G?
    If CtrlDown And AltDown Then
    ' Your special action here
    Beep
    ' Prevent key from being processed further
    KeyCode = 0
    End If
    Case vbKeyPageDown, vbKeyPageUp
    ' Prevent key from being processed
    KeyCode = 0
    End Select
    End Sub

  11. #11
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

    You are the man! Thanks Hans. Things are getting clearer...

    Im doing VB and Access and programming etc at College, and have hands on projects here at work....but i find this forum very helpful, so

    Thanks again <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Thanks,

    pmatz

  12. #12
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Write Confilct (XP 2000)

    I have noticed that the mouse scroll wheel has the same effect as the page up/down keys. Is there an equivalent to the key press method of stopping these having effect for the mouse scroll wheel?
    Thanks,

    pmatz

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

    Re: Write Confilct (XP 2000)

    See MouseWheelOnOff on Stephen Lebans' website and download MouseWheelHook.zip. It contains a DLL that you must copy into your system folder and a demo database that shows how to use it.

Posting Permissions

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