• Extremely odd! Code fails for no good reason

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Extremely odd! Code fails for no good reason

    Author
    Topic
    #464453

    Problem solved – used instr on control names rather than polling by Tag. Theory: MS doesn’t tolerate more than one tag setting for a form, or something equally goofy.

    I have this:

    Code:
    Public Function CheckUserEdits()
    Dim UserCtlString As String
    Dim UserCtl As Control
    Dim ctl As Control
    Dim ContainsNulls As Integer
    
    For i = 0 To 7
    For Each ctl In Forms!RUG.MainTab.Pages(i).Controls
    With ctl
    If .Tag = "OR" Then
    If IsNull(.Value) Then
    ContainsNulls = 1
    Debug.Print "Control name: " & .Name
    Debug.Print "Control value: " & .Value
    End If
    End If
    End With
    Next
    Next i
    
    End Function

    just debug.print to see if the loop events work. they do. each form control has a smart tag and tag set to OR.

    Now! when i do this:

    Code:
    Public Function CheckUserEdits()
    Dim UserCtlString As String
    Dim UserCtl As Control
    Dim ctl As Control
    Dim ContainsNulls As Integer
    
    For i = 0 To 7
    For Each ctl In Forms!RUG.MainTab.Pages(i).Controls
    With ctl
    If .Tag = "UE" Then <-- that's the ONLY ONLY ONLY change
    If IsNull(.Value) Then
    ContainsNulls = 1
    Debug.Print "Control name: " & .Name
    Debug.Print "Control value: " & .Value
    End If
    End If
    End With
    Next
    Next i
    
    End Function

    The code fails: “Object does not support this property or method”. The control tags are “UE” in Smart Tags and Tags. several controls are drop-downs, but not all. i can’t even get a list based on the control tag, and changing UE to something like, say, WTA, doesn’t help either.

     

    Viewing 2 reply threads
    Author
    Replies
    • #1188898

      I’ve tested your code and I have no problem. Can you post a stripped version of your DB where the error occur ?

    • #1188923

      Since I implemented a hack to get around this weird problem, I’m moving on to other things. I really shouldn’t try to do this sort of work on Friday…

    • #1189221

      Can you clarify what the problem was here?
      Was it that you wanted some controls to have both “UE” and “OR” in their Tag, so they belonged to both groups?
      In that case, yes you would need to use:

      Code:
      If (InStr(1, .Tag, "OR") > 0) Then

      rather than

      Code:
      If .Tag = "OR" Then

      I often use code like this (looping through controls checking for something in their Tag property), so I am just wondering if there is some pitfall here I was not aware of.

      • #1190347

        Can you clarify what the problem was here?
        Was it that you wanted some controls to have both “UE” and “OR” in their Tag, so they belonged to both groups?
        In that case, yes you would need to use:

        Code:
        If (InStr(1, .Tag, "OR") > 0) Then

        rather than

        Code:
        If .Tag = "OR" Then

        I often use code like this (looping through controls checking for something in their Tag property), so I am just wondering if there is some pitfall here I was not aware of.

        I have a set of controls that are “OR” and another set that are “UE”. there’s no overlap. some other controls have no tag at all, and the first code block (which polls based on Tag info) does, correctly, ignore controls with no tag data. it’s just that if i try to poll UE controls using the Tag technique it mysteriously fails. since i have prepends on those controls, i can still pick them up in a loop but it’s a weird thing to have to do…

        • #1190385

          it’s just that if i try to poll UE controls using the Tag technique it mysteriously fails. Since i have prepends on those controls, i can still pick them up

          There is nothing special about using UE as a tag. The standard code works OK for me with that tag.

          What is a ‘prepend”?

          I am puzzled by this thread, and am interested in getting to the bottom of it. But if you are not, and just want to move on, don’t bother replying.

    Viewing 2 reply threads
    Reply To: Extremely odd! Code fails for no good reason

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: