#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    334
    Rep Power
    246

    Event Procedures - Access 2010


    I seem to be having issues with event procedures and focusing on form fields.

    It seems that if within an event procedure I call another global function which focuses on a form field and moves the carret to the end, as the code eventually goes back to the event procedure call, if I do anything else within the event procedure the text highlighted in the form field is random and peculiar?

    If the event procedure after calling the global function does nothing else the correct point in the focused field is where the carret is placed.

    Is this normal?

    Is it something to do with being an event handler call rather than a standard function/sub call.

    It only seems to behave like this if done within an event handler as described?

    Thanks
    1DMF.
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    You need to be a little more specific before we can help you. An Event procedure is nothing more than a function call triggered by an event raised within the Windows messaging system.
  4. #3
  5. No Profile Picture
    Stumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    It depends on the event. If you're using an onChange event on the text field you're modifying from the event procedure code you have to be kinda careful that you don't get in an event loop.

    But without specific examples and code it's hard to say for sure.
    ======
    Doug G
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    334
    Rep Power
    246
    It is double click event.

    Basically I have a form with a field when it is double clicked it opens another form and binds the clicked control to it, when that form closes the rest of the doubleclick code executes but the cursor isn't in the right place.

    here is the code...

    Code:
       Private Sub docNotes_DblClick(Cancel As Integer)
    
        Call inputZoom("Documents Request Notes")
    
        Do Until Not IsLoaded("inputPopUp")
            DoEvents
        Loop
    
        If bPopZoomChanged Then
        
            Call setDocs(Me.Docs_Form.Form, Me.Adviser)
            
            If Nz(Me.docNotes, "") <> "" Then
                Me.docNotes.SetFocus
                Me.docNotes.SelStart = Len(Me.docNotes)
            End If
        
        End If
        
    End Sub
    But I gave up with this in the end, I guess trying to pause an event handler isn't a good idea / practice.

    I changed the doubleclick event to only run the inputZoom call and then added this to the form close event...
    Code:
    Private Sub Form_Close()
    
        If bPopZoomChanged And oControl.Name = "docNotes" Then
            [Forms]![Check_Docs].Last_Check = Format(Now(), "dd/mm/yyyy")
            [Forms]![Check_Docs].Checked_By = oUser.Name
        End If
        
        oControl.SetFocus
        If Not IsNull(oControl) Then
            oControl.SelStart = Len(Me.inputTextBox)
        End If
        
    End Sub
    So now the last thing the chained call of event handers do is focus on the field and it works as desired.
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    Originally Posted by 1DMF
    But I gave up with this in the end, I guess trying to pause an event handler isn't a good idea / practice.
    That is correct. Your problem was the loop:
    Do Until Not IsLoaded("inputPopUp")
    DoEvents
    Loop
    Just as in interrupt driven routines, you should always return as quickly as possible. If you need to wait for something else, set a flag and process it elsewhere. VB will not process other functions until the one that it is currently processing is complete. The DoEvents statement only allows system functions to be addressed.

    J.A. Coutts
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    334
    Rep Power
    246
    thanks J.A. Coutts, I thought that might be the issue, but it's always nice to have things confirmed!
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!

IMN logo majestic logo threadwatch logo seochat tools logo