Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44

    Unanswered: Can anyone help?



    I have been working on some code to disable buttons on a form and so far with the help of you guys got 90% of it working. Now i have added a DCount to the code but keep getting compile errors. The code is run from a button on the form and without the DCount part works fine. I think its because i am using the for/next approach to calculate the field name.

    Any help would be much appreciated
    Code:
    For X = 1 To 14
      If Me("dayname" & X) = "Sunday" Or Me("dayname" & X) = "Monday" or _
     DCount("[downtime]","tbldowntime","[downtime] =Me("day" & X)Then
        Me("cmdday" & X & "am").Enabled = False
        Me("cmdday" & X & "pm").Enabled = False
        Else: Me("cmdday" & X & "am").Enabled = True
        Me("cmdday" & X & "pm").Enabled = True
    End If
    Next
    Thanks

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Try something like this

    Code:
    For X = 1 To 14
        If (Me("dayname" & X) = "Sunday") OR (Me("dayname" & X) = "Monday") OR _
                (DCount("[downtime]","tbldowntime","[downtime] = " & Me("day" & X))) Then
            Me("cmdday" & X & "am").Enabled = False
            Me("cmdday" & X & "pm").Enabled = False
        Else
            Me("cmdday" & X & "am").Enabled = True
            Me("cmdday" & X & "pm").Enabled = True
        End If
    Next
    I think it had a problem with your string argument.

    What is the DCount test supposed to be testing? Right now it's not really testing anything (well it sort of is, but only if you understand boolean expressions and the values of TRUE and FALSE, but generally I like to explicitly write out the test). If the count is greater than 0 perhaps? If that is the case then do more like

    Code:
    For X = 1 To 14
        If (Me("dayname" & X) = "Sunday") OR (Me("dayname" & X) = "Monday") OR _
                (DCount("[downtime]","tbldowntime","[downtime] = " & Me("day" & X)) > 0) Then
            Me("cmdday" & X & "am").Enabled = False
            Me("cmdday" & X & "pm").Enabled = False
        Else
            Me("cmdday" & X & "am").Enabled = True
            Me("cmdday" & X & "pm").Enabled = True
        End If
    Next
    Give that a shot.
    Me.Geek = True

  3. #3
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44
    that's fixed the error but it still not doing what i had hoped.

    What i need it to do is using the field(criteria) "[downtime] = " & Me("day" & X)) > 0) count if any records exist matching the form field in the table "tbldowntime", if they do then disable the button, if they don't then enable the button) for some reason when i add the DCount section to the code all the buttons disable.

    Tried both suggestions but still no luck

  4. #4
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44
    p.s in my code i included the >0 part but no joy

  5. #5
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44
    resolved thanks for your help

Posting Permissions

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