Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SetFocus question (Access XP)

    Can someone point out what I'm doing wrong here on a form.

    I've put a bit of code in to check a numeric value. If the amount doesn't match an existing figure then I reset the field to a blank field, then try to set the focus to that field.

    Private Sub RenewAmt_AfterUpdate()
    If RenewAmt <> Donation Then
    MsgBox "Renewal amount is not the same as the existing contribution"
    RenewAmt = ""
    RenewAmt.SetFocus
    End If
    End Sub

    Everything works fine except the "RenewAmt.SetFocus" line. I've used debug on it and it executes ok but doesn't move the focus.

    What could I be missing?

    Colin

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

    Re: SetFocus question (Access XP)

    Since you want to be able to cancel the update, you must use the Before Update event instead of the After Update. It has a Cancel argument that you can set to True. The focus will stay in the RenewAmt control then, so you don't need SetFocus:

    Private Sub RenewAmt_BeforeUpdate(Cancel As Integer)
    If RenewAmt <> Donation Then
    MsgBox "Renewal amount is not the same as the existing contribution"
    RenewAmt = Null
    Cancel = True
    End If
    End Sub

    But if RenewAmt must *always* be the same as Donation, why let the user modify it at all? Why have a RenewAmt field, even?

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus question (Access XP)

    Its an annual renewal payment, and until today, it didn't have any validation. Then an existing member renewed for an amount 20% of his existing payment, and the system never caught it as there was no check.

    The idea now is to verify that the payment made is actually the same as the current subscription.

    The renew Amount field is actually an unbound field, so that in fact, the user never alters the original amount


    Thanks for the help tho.


    COlin

  4. #4
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus question (Access XP)

    Hans

    Can you check one more thing for me please. When I changed the code, I get the error msg below.

    There is some validation on the field, but it works first (i've deleted it as well to try that).

    If I rem out the RenewAmt = Null line, the code works fine, but the cursor is at the end of the field.

    The help button takes me to an empty page.

    I've tried a google search on the code, and get a number of matches, but none of them seem to be similar to my error.

    The field is a Currency format, and its unbound. Could that be any part of the problem? Or References?

    Yours, puzzled !!!!!!!!!!!


    Colin
    Attached Images Attached Images

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

    Re: SetFocus question (Access XP)

    Sorry, it is my fault, not yours. I hadn't actually tested the code. It turns out that it is not possible to change the value of the control this way. You can restore the previous value (blank if it is being filled in for the first time) by using RenewAmt.Undo instead of RenewAmt = Null. Alternatively, if you would like the entire text to be selected, use

    Me.RenewAmt.SelStart = 0
    Me.RenewAmt.SelLength = Len(Me.RenewAmt.Text)

  6. #6
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus question (Access XP)

    Hans

    Ah That's better!

    You've no idea how much better it makes me feel that the experts can get it wrong as well.

    I am only playing at being a coder here, and while I can often work out a soilution, SOmetimes, you can waste hours on apparently simple problems. I enjoy trying to solve these problems however and I always try to solve it myself first.

    Thanks again

    Colin

Posting Permissions

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