VBA - Crashing infrequently

Re: Macro - Crashing infrequently

Yeah... also half of the posts have been deleted/disapeared

I did ask a mod to move/rename it.. something funny has happened as your post is at the top now :O
 
Re: Macro - Crashing infrequently

Oh yeah that's right. Half of the posts are missing. I'm sure one of the mods will sort it out anyway.

By the way, remember that the error handling needs to go into any function/sub that you suspect will error. To be honest, even if you don't anticipate it, best to have an error handler in place. And look for a way to use Allen Browne's error handling code instead of just the standard one you have. For me I have a whole class for error handling which spews it to a formatted text file.
 
Re: Macro - Crashing infrequently

Thanks VBA.

At present I have injected the simple one into problematic codes (as a stop gap)

I want to eventually create one which will create log files/error files like yours when it occurs so I can then trace them easier. I will begin testing some of Allen Browne's code as soon as I feel confident enough. and of course will return here for help with it ;)

Thanks so much. I won't mark this issue as solved but without the setfocus then I don't see how this error message could appear. BUT new errors may pop up.
 
Re: Macro - Crashing infrequently

On a side note: I swear the people who use this stuff don't appreciate how much effort and hours of coding is implimented into each one.
 
Re: Macro - Crashing infrequently

Up to you! Allen Browne's one writes to a table so it's pretty much a "similar" concept.
 
Re: Macro - Crashing infrequently

On a side note: I swear the people who use this stuff don't appreciate how much effort and hours of coding is implimented into each one.
Some do, some don't. Just depends on the person.
 
Re: Macro - Crashing infrequently

Up to you! Allen Browne's one writes to a table so it's pretty much a "similar" concept.

Oh I like the sound of that, rather than having a folder of log files everywhere.

Will do a lot more indepth research.
 
Hi All...
Are all the posts for this thread present and correct?
 
Hi All...
Are all the posts for this thread present and correct?
It seems to follow a logical response pattern from pages 1 through to 4 so I think it's all here. We'll wait to see what Kacey thinks.
 
Ah good!!!

I'm going now before RainLover turns up...
 
Hi Guys

A couple of comments.

The error handling I posted was written by ChrisO. It is good and simple.

When in design mode and you need to get rid of some code just Rem it out rather than delete it. you may find that the code was good so you may want it back.

You can always delete it as a final clean up.
 
Re: Macro - Crashing infrequently

Even thought I am in the change event for SearchFor and the code is setting the focus for SearchResults A totally different box?

This isn't my code of course, but it looks as if the Setfocus code is used to swap between the Searchfor (text box) and the SearchResults (list box)

I added the code with the code notes, please note the code isn't mine but modified from one of the guides from here

Code:
Private Sub SearchFor_Change()
On Error GoTo Err_SearchFor          [COLOR=green]' Initialize error handling.[/COLOR]
[COLOR=green]'Create a string (text) variable[/COLOR]
    Dim vSearchString As String
[COLOR=green]'Populate the string variable with the text entered in the Text Box SearchFor[/COLOR]
    vSearchString = SearchFor.Text
[COLOR=green]'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll[/COLOR]
    SrchText.Value = vSearchString
[COLOR=green]'Requery the List Box to show the latest results for the text entered in Text Box SearchFor[/COLOR]
    Me.SearchResults.Requery

[COLOR=green]'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
[/COLOR]    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
     [COLOR=green]   'Set the focus on the first item in the list box
[/COLOR]            Me.SearchResults = Me.SearchResults.ItemData(1)
            Me.SearchResults.SetFocus
       [COLOR=green] 'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box[/COLOR]
            DoCmd.Requery
[COLOR=green]        'Returns the cursor to the the end of the text in Text Box SearchFor,
        'and restores trailing space lost when focus is shifted to the list box
[/COLOR]            Me.SearchFor = vSearchString
            Me.SearchFor.SetFocus
            Me.SearchFor.SelStart = Me.SearchFor.SelLength
            
        Exit Sub
    End If
[COLOR=green]'Set the focus on the first item in the list box
[/COLOR]    Me.SearchResults = Me.SearchResults.ItemData(1)
    Me.SearchResults.SetFocus
[COLOR=green]'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box
[/COLOR]    DoCmd.Requery
[COLOR=green]'Returns the cursor to the the end of the text in Text Box SearchFor[/COLOR]
    Me.SearchFor.SetFocus
    If Not IsNull(Len(Me.SearchFor)) Then
        Me.SearchFor.SelStart = Len(Me.SearchFor)
    End If
Exit_SearchFor:                          [COLOR=green] ' Label to resume after error.
[/COLOR]     Exit Sub                            [COLOR=green] ' Exit before error handler.
[/COLOR]Err_SearchFor:                          [COLOR=green]  ' Label to jump to on error.[/COLOR]
     MsgBox Err.Number & Err.Description  [COLOR=green]' Place error handling here.[/COLOR]
     Resume Exit_SearchFor              [COLOR=green]  ' Pick up again and quit.[/COLOR]
End Sub

Your comments are very informative. However they are more like instructions on how to code by explaining every line.

Your objective should be more along the lines of explaining in a general sense what the code does and only explain the more difficult parts.

If you were to repeat what has been done you will be there for a month of Sundays.

Some code like Close the Form would require no explanation. In some cases the remarks could be quite detailed.

It would be good if you could improve on your indenting and spacing. Some just call it White Space.
 
I even used a smiley face once.

Yes I saw it... A good likeness by all accounts...
fHQuqdy2XilEmxhZD-gNAzifh1hCBb3aW_eWc9V5CK1B=s192-p-no
 
"Yes you're right Uncle, a very good likeness of yourself...
 

Users who are viewing this thread

Back
Top Bottom