Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41

    Check two combo box if null

    Why its not working? here is the code


    its working before when companynameid and countryid is still integer but i had to change to string now the code is not working.

    Code:
    If IsNull(Company_Name.Value And Country.Value) Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If

  2. #2
    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
    Which value is a string now?

  3. #3
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by RuralGuy View Post
    Which value is a string now?
    Company_Name and Country

  4. #4
    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
    Try:
    Code:
    If Len(Company_Name.Value & Country.Value) = 0 Then
       btnAdd.Enabled = False
    Else
       btnAdd.Enabled = True
    End If

  5. #5
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by RuralGuy View Post
    Try:
    Code:
    If Len(Company_Name.Value & Country.Value) = 0 Then
       btnAdd.Enabled = False
    Else
       btnAdd.Enabled = True
    End If
    I add text in company_name and country is null, its enabling the btnAdd

  6. #6
    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
    Did you try what I suggested?

  7. #7
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by RuralGuy View Post
    Did you try what I suggested?
    yes i use your code

  8. #8
    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
    So is my code working for you? Are you good to go?

  9. #9
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by RuralGuy View Post
    So is my code working for you? Are you good to go?
    It's not working, the button is enabled. i only put text in the company name

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Please show us/post the code you are using.

  11. #11
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by orange View Post
    Please show us/post the code you are using.
    If Len(Company_Name.Value & Country.Value) = 0 Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If

  12. #12
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    TRY this: (guessing)
    Code:
    If Len(Me!Company_Name & Me!Country) = 0 Then
          btnAdd.Enabled = False
    Else
          btnAdd.Enabled = True
    End If
    Where exactly are you running this code? That is, which event?
    I see you said they are 2 combo boxes, which are usually prefixed cboXXXX ans cboYYY.

    Perhaps you could post a copy of the db so we can see the details and context.

  13. #13
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by orange View Post
    TRY this: (guessing)
    Code:
    If Len(Me!Company_Name & Me!Country) = 0 Then
          btnAdd.Enabled = False
    Else
          btnAdd.Enabled = True
    End If
    its still enabling thebtnAdd,i only put text in the company name

  14. #14
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Another try: Based on both must have values

    Code:
    If Len(Me!Company_Name = 0  OR _
       Len( Me!Country) = 0 Then
          btnAdd.Enabled = False
    Else
          btnAdd.Enabled = True
    End If

  15. #15
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by orange View Post
    TRY this: (guessing)
    Code:
    If Len(Me!Company_Name & Me!Country) = 0 Then
          btnAdd.Enabled = False
    Else
          btnAdd.Enabled = True
    End If
    Where exactly are you running this code? That is, which event?
    I see you said they are 2 combo boxes, which are usually prefixed cboXXXX ans cboYYY.

    Perhaps you could post a copy of the db so we can see the details and context.

    Code:
    Private Sub Company_Name_Change()
    If Len(Company_Name.Value & Country.Value) = 0 Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If
    
    End Sub
    Private Sub Company_Name_LostFocus()
    If Len(Company_Name.Value & Country.Value) = 0 Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If
    End Sub
    
    Private Sub Country_Change()
    If Len(Company_Name.Value & Country.Value) = 0 Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If
    End Sub
    
    Private Sub Country_LostFocus()
    If Len(Company_Name.Value & Country.Value) = 0 Then
    btnAdd.Enabled = False
    Else
    btnAdd.Enabled = True
    End If
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 06-30-2017, 10:56 AM
  2. Check if unbound textbox is null
    By matt_wpg in forum Programming
    Replies: 8
    Last Post: 06-21-2017, 08:23 PM
  3. Replies: 4
    Last Post: 01-14-2014, 01:28 PM
  4. How to Check If Two Fields are Null?
    By alpinegroove in forum Programming
    Replies: 5
    Last Post: 01-04-2012, 01:41 PM
  5. Null Check
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 06-04-2010, 12:59 PM

Tags for this Thread

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