Multiple condition query

sathyaganapathi

Board Regular
Joined
Apr 29, 2021
Messages
81
Office Version
  1. 2016
Platform
  1. Windows
Hi,
Could you please help to combine below two quries under one?
VBA Code:
If Me.ComboBox1.Value <> "Lab_Pending" And Me.ComboBox1.Value <> "ALL" Then
    qry = "SELECT * FROM TBL_PlabInput WHERE " & Me.ComboBox1.Value & " LIKE '%" & Me.TextSearch.Value & "%'"
End If

Code:
If Me.ComboBox1.Value = "ALL" And sDate <> "" And Me.ComboBox1.Value = "ALL" And eDate <> "" Then ' this is working
    qry = "SELECT * FROM TBL_PlabInput where Process_DateTime BETWEEN #" & sDate & "# AND #" & eDate & "#"
End If

Both are working fine when user separately.
when try to combine them together nothing worrks.
What I want is, first query to work when date range is given.
Please help.
 

Attachments

  • combobox1value.jpg
    combobox1value.jpg
    17.6 KB · Views: 18
.Value is the default property for most (all?) data controls. It's just that you don't need to use it but it's not wrong, just not common to do so.

I think that your issue was that you forgot the AND (logical) operator and used the concatenation operator (&) instead

Me.TextSearch & "%' & Process_DateTime BETWEEN
vs
Me.TextSearch & "%' AND Process_DateTime BETWEEN
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
.Value is the default property for most (all?) data controls. It's just that you don't need to use it but it's not wrong, just not common to do so.

I think that your issue was that you forgot the AND (logical) operator and used the concatenation operator (&) instead

Me.TextSearch & "%' & Process_DateTime BETWEEN
vs
Me.TextSearch & "%' AND Process_DateTime BETWEEN
Dear Micron,
Got it... Thanks a lor for your support.
Have a nice day.
 
Upvote 0

Forum statistics

Threads
1,224,620
Messages
6,179,925
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top