Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42

    Code works only when manually stepping through it

    I have a short code in Access that only works when stepping through it.



    But, when running it, it does not work. The combobox selects a last name.
    The subform field "ConfCode" appears correctly in the subform but the code
    does not provide the string equivalent as shown in the code below.


    Code:
    Private Sub Combo32_AfterUpdate()
            TxtConstitCode.Value = " "
            If [sfmVolun/BoardMem-CC].[Form]![ConfCode] = "V" Then
                     TxtConstitCode.Value = "Volunteer"
            ElseIf [sfmVolun/BoardMem-CC].[Form]![ConfCode] = "B" Then
                     TxtConstitCode.Value = "Board Member"
            End If
    End Sub
    It will also work when the value in Combo32 is clicked on twice.
    TxtConstitCode appears to keep its previous value but will display
    its correct value when the same value is selected again in the combo
    box.

    Why it works correctly in stepping through the code is a mystery to me.

    Hope somebody can shed some light on this anomaly.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    When this symptom occurs, it is likely due to performance. Why are you using the fully qualified name of the control ConfCode?

    Is this control already displaying the value you wish to analyze?

    I might start moving towards something along the lines of ...
    Code:
    Dim strMyVariable As String
        If Me.ConfCode <> "" Then
            strMyVariable = Me.ConfCode
        End If
    
            If strMyVariable = "V" Then
                TxtConstitCode.Value = "Volunteer"
            ElseIf strMyVariable = "B" Then
                TxtConstitCode.Value = "Board Member"
            Else
                TxtConstitCode.Value = ""
            End If

  3. #3
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Thank you for the response.

    The control is already displaying the value I wish to analyze.
    My choice of the fully qualified name of the control is that it
    is what I believe to be the correct way to identify a subform control.
    The subform is linked to the combo box via the field "Last Name."

    I tired your code and it did not work. No matter what the ConfCode
    value was the TxtConstitCode field did not change.

    I am still wondering why my code works in step mode and also when
    the value in the combo box is clicked twice. These clues indicate that
    something is missing in my code.


    I tried your code and it did not work

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by ItsMe View Post
    When this symptom occurs, it is likely due to performance.
    As ItsMe suggested, when things run when stepping through code, but not when running 'normally,' it's usually a performance problem, aka a timing problem. But what does the value selected in Combo32 have to due with [ConfCode] or TxtConstitCode??? It is most unusual for the value of any Control to be assigned by the AfterUpdate event of a Control if that Control isn't directly involved!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Aside from Missinglinq's important comment, you may have a corrupt combobox control.

    Regarding the code you used to reference your subform, it seems your code is correctly referencing the subform control. You are seemingly implying the Me shortcut by not including it. In other words, the code I provided should throw a compilation error.

  6. #6
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    The value in the combobox links to a record in the subform with the same value. In
    that record is the ConfCode for that record. And that ConfCode is correct for the
    combobox value selected.

    I suspect some timing issue, also. However, I don't know how to resolve it or how
    to get around it.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    As far as the code executing and behaving in a predictable way, your original code should behave in a predictable way. Saving a copy of your DB, saving your code that is related to your combobox in a text file, deleting your combobox control, compacting and repairing your DB, and then rebuilding your combo may help your cause.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    Sometimes using non alphanumeric characters in table, field and control names can cause unexpected issues. Try changing the name of your subform from [sfmVolun/BoardMem-CC] to something that does not include / and -.

    Another possibility is that a current record has not been identified in your subform to return a value, at least not a V or B

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Ajax View Post
    Sometimes using non alphanumeric characters in table, field and control names can cause unexpected issues. Try changing the name of your subform from [sfmVolun/BoardMem-CC] to something that does not include / and -.
    ...
    I was pondering that, too. With all things being equal and the code truly working during debug mode, I wonder if this is the case. Regardless, this issue and others should be addressed. For instance, using magic strings as key values.

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I was pondering that, too.
    Just putting it out there! - I've seen several posts on this and other forums where removing the offending characters solves the problem. I ought to keep a list!

    However I also agree that it is likely to be a timing issue - I suspect the combo is the linkparent property of the subform - if so which runs first? does the requery of the subform occur before the combo afterupdate event fires? or the other way round? or do they run concurrently (don't think they can)

    Assuming my suspicion is correct I would remove the code from the after update event and put the following in the subform current event

    Code:
    select case ConfCode
        case "V"
            parent.TxtConstitCode = "Volunteer"
        case "B"
            parent.TxtConstitCode= "Board Member"
        case else
            parent.TxtConstitCode = ""
    end select

  11. #11
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Removed the "/" and "-" but no improvement.
    The subform returns a value. It's visible on the form.

  12. #12
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Could you explain what "magic strings as key values" means?
    And, what changes I can make in this regard.

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by john134 View Post
    Could you explain what "magic strings as key values" means?
    And, what changes I can make in this regard.
    Magic strings are things like "V" and "Volunteer" and " ". Instead, you should use Integers as Keys. For instance, a selection on a combobox would cause the .Value of the combo to be a relevant Key value, like 203 or 10452. These key values are indexed and unique. This is the most simple explanation I can think of. As for addressing the issue you are experiencing. I would attempt to delete the combo and rebuild it, as described in post #7.

    Take a look at post #10. I would consider something along these lines, also. You are placing a lot of responsibility on the afterupdate of your combo. It is hard to explain. I am not referring to the control demanding too much RAM or processing power. I am talking about separating out the concerns of your application. In other words, V = Volunteer and B = Board Member. This can be determined somewhere else in the application. It can be in a table using a Primary Key, in the form of a constant, and other ways as well.

  14. #14
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Thank you very much. You have come up with the solution!!

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by john134 View Post
    Thank you very much. You have come up with the solution!!
    Did you want to share that solution with the helpers in this thread?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 08-07-2015, 03:28 PM
  2. Replies: 11
    Last Post: 12-11-2013, 10:35 AM
  3. similar code, one works, the other doesn't
    By johnseito in forum Access
    Replies: 15
    Last Post: 11-03-2013, 07:59 PM
  4. Replies: 9
    Last Post: 06-26-2012, 04:11 PM
  5. Code works in full, fails in Runtime
    By stephenaa5 in forum Programming
    Replies: 3
    Last Post: 09-14-2010, 12:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums