Results 1 to 8 of 8
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Checkbox with conditional If and Dlookup with two conditions

    Hi everyone,

    I have question regarding a code I am trying to do and it's driving me crazy...



    I have a table named as "Work_Team" which contains a lot of people from a company with diferent departments; the most of them have assigned a Production line like the Quality department, Engineering, Production Department, etc. There are other departments more generic that can attend everybody and not neccesary needs to assign a "production line" like warehouse and human resources or sales, etc.

    I inserted some checkboxes (One by department) into a form named "Main_Form", The idea is to assign people into a Textbox named "TeamM" and it should select this people from the table "Work_Team" where the production line coincide with the form's droplist "Me.ProductionLine"

    As a example one of this checkboxes is "WT_Warehouse" so I what I want to do is...

    if the person assigned to the Warehouse has any productionline the "event" take the person by default from warehouse
    but if I assigned into my table a production line for the warehouse guy the "event" would look for the guy where the department is Warehouse AND Production_Line coincide with Me.Line_Production

    Also when I unselect the checkbox this guy should be removed


    This is my code, I made that by parts but all together does not work... Your help is highly appreciated

    ************************************************** *****************************
    Private Sub WT_Warehouse_Click()

    Dim Warehouse1 As String
    Dim StrWarehouse1 As String
    Dim Warehouse2 As String
    Dim StrWarehouse2 As String

    'Clicking on the Warehouse checkbox and the field TeamM is empty

    If Me.WT_Warehouse = -1 And Len(Me.TeamM & vbNullString) = 0 Then

    'Here the field "Name" from the table Work_Team is the person responsible of the Warehouse department and it would work if this guy has a production line assigned, if not, should move to the next condition

    Me.TeamM = DLookup("[Name]", "[Work_Team]", "[Department]= 'Warehouse' And [Line_Production]= '" & Me.Line_Production & "'")

    'If the line below is empty it should move to the line below; I do not know if this is the issue...

    ElseIf Me.TeamM = DLookup("[Name]", "[Work_Team]", "[Department]= 'Warehouse'") Then

    StrWarehouse1 = DCount("[Name]", "[Work_Team]", "[Department]= 'Warehouse' And [LineProduction]= '" & Me.Line_Production & "'")

    'Here should start the next condition... If I unclick on the checkbox to eliminate from the "TeamM" textbox the guy from warehouse


    ElseIf Me.WT_Warehouse = 0 And StrWarehouse1 >= 1 Then

    Me.TeamM = Replace(Me.TeamM, StrWarehouse1, "")
    Me.TeamM = Replace(Me.TeamM, Chr(10), "")
    Me.TeamM = Replace(Me.TeamM, Chr(13), "")

    ElseIf Me.WT_Warehouse = 0 And StrWarehouse1 = 0 Then

    Warehouse2 = DLookup("[Name]", "[Work_Team]", "[Department]= 'Warehouse' ")

    Me.TeamM = Replace(Me.TeamM, Warehouse2, "")
    Me.TeamM = Replace(Me.TeamM, Chr(10), "")
    Me.TeamM = Replace(Me.TeamM, Chr(13), "")

    End If

    'I highly appreciate if you can help me to correct what it is wrong from my code

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    How is this question different from your other thread https://www.accessforums.net/showthread.php?t=80494 ?

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Hi June7

    It 's different in the way that I just put into a part of the code... but all together does not work, maybe I should start my last thread with all the explaination I included in this new one
    Could you help me on this new one?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    "Does not work" means what - error message, wrong result, nothing happens? Have you set a breakpoint and step debugged? Follow the code as it executes. Does is do what is expected?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    It is stopping when I unclick on the WT_Warehouse in this line

    'Here should start the next condition... If I unclick on the checkbox to eliminate from the "TeamM" textbox the guy from warehouse
    ElseIf Me.WT_Warehouse = 0 And StrWarehouse1 >= 1 Then

    Do you know what would be changed?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    What do you mean by "stopping" - is there an error message?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Nop is just point this line in yellow out

    ElseIf Me.WT_Warehouse = 0 And StrWarehouse1 >= 1 Then

    When I review the code it is showing as result ""

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    There has to be some sort of message.

    StrWarehouse1 is declared as a String yet your expression tests for a numeric value. In another place you set the variable to a number with DCount(). Declare the variable as an Integer.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Conditional If with two conditions and Dlookup
    By charly.csh in forum Access
    Replies: 7
    Last Post: 05-02-2020, 10:24 PM
  2. Replies: 1
    Last Post: 04-30-2014, 05:26 PM
  3. conditional formatting of a checkbox
    By survivo01 in forum Forms
    Replies: 7
    Last Post: 02-07-2013, 04:29 PM
  4. Conditional Formatting with more than 3 conditions
    By cactuspete13 in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 01:03 PM
  5. Replies: 1
    Last Post: 03-27-2012, 04:49 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