Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002

    Unanswered: get control value from code, update form and the setfocus if

    I calculate an age in the on after update event of a control on a subform and if certain conditions are met I am trying to open a msgbox and then set focus back to another control on the same subform.

    I'm having two problems:

    It can calculate the proper age but when I try to put this value in the age control in the same subform in the on update event of the birthday control the value doesn't appear until I have added a new record. I've tried adding:


    but I get an error stating that I must first save the current field before running the requery action.

    I also want to open a message box then set the focus back to another control on the same subform.

    I've tried:

    Forms![Camp Blodgett Preliminary Data Entry Form]![new child].Form![Session].SetFocus

    but I get an "object doesn't support this property or method" error

    It looks like the after update event doesn't like requery (or repaint or refresh)

    Can anyone give me some help with this?


  2. #2
    Join Date
    Dec 2004
    Madison, WI
    You can try the: Refresh command after your calculation and writing to the field. This saves the data and you may not even need to requery the subform. If you're doing this on a new record, you want to make sure any required fields are first filled in before issuing a Refresh command. (Note: Refresh only works on the form you're currently editing. You cannot do this: Forms!MyMainform!MySubform.Refresh. If you're calculation coding is 'outside' the subform, you'll either have to put that calculation as a function within the subform so you can utilize the Refresh command, or you'll need to find a way to get the focus back to the subform and issue a Refresh command (ie. calling a Public Function within the subform which has the Refresh command).

    To set the focus to the field on the subform: Forms!MyMainFormName!MySubformName!MyFieldName.set focus (remember: you can't set the focus to the control if it already has the focus - ie. You must set the focus to another control and then to the control you want to.)

    If the above doesn't work, try first setting the focus to the mainform (or subform), then the control:
    Forms!MyMainFormName!MySubformName!MyFieldName.set focus

    Sometimes MSAccess get's stubborn and you must set the focus to the form/subform first. Of course, you need to make sure the field CAN actually get the focus (ie. it's Enabled property = True).

    To write a value to the field on the subform: Forms!MyMainFormName!MySubformName!MyFieldName = Forms!SomeOtherForm!SomeOtherSubform!OtherFieldNam e
    Last edited by pkstormy; 03-27-10 at 03:32.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Tags for this Thread

Posting Permissions

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