By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,501 Members | 2,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,501 IT Pros & Developers. It's quick & easy.

Need Help About Combobox With Dates

P: 16
I need help urgent. I don't know how to filter a form with combobox By dates', cause I understood that the value of combobox should be a number, so what should I do if my values are dates? Please Help!
Feb 14 '07 #1
Share this Question
Share on Google+
10 Replies


maxamis4
Expert 100+
P: 295
Combo boxes are controls bound to queries. You should be able to go to the properties of the combo box and go to its control source and have it sort the date by descending value. That should sort the combo box for you.
Feb 14 '07 #2

Rabbit
Expert Mod 10K+
P: 12,315
Combo boxes don't have to be a number. But aside from that, Dates are stored as a number. So either way, no problem.
Feb 14 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
Check out (Example Filtering on a Form.) for the full information on this topic.
Feb 14 '07 #4

P: 16
Check out (Example Filtering on a Form.) for the full information on this topic.
Thanks a lot.my problem was solved. I have another problem if you can help me. I am filtyering a form by few combo boxes by creating a long string from all the values of the combos. at the last combo I get a RunTimeError 2001:"You Cnceled previouse Operation". what's that mean?
Feb 15 '07 #5

P: 16
Combo boxes don't have to be a number. But aside from that, Dates are stored as a number. So either way, no problem.
Thanks a lot.You was absoloute correct. my problem was solved. I have another problem if you can help me. I am filtering a form by few combo boxes by creating a long string from all the values of the combos. at the last combo I get a RunTimeError 2001:"You Cnceled previouse Operation". what's that mean?
Feb 15 '07 #6

NeoPa
Expert Mod 15k+
P: 31,186
Perhaps you could post the code you use for this, just to give us a clue.
Feb 15 '07 #7

P: 16
Perhaps you could post the code you use for this, just to give us a clue.
Thanks a lot.This is the Code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub FilterProcessForm()
  2.  
  3.     Dim strTotalFilter As String
  4.     Dim strMonthFilter As String
  5.     Dim strDepartmentFilter As String
  6.     Dim strProjectTypeFilter As String
  7.     Dim strCustomerFilter As String
  8.     Dim strProjectFilter As String
  9.     Dim strInvoiceFilter As String
  10.  
  11.     '--------MonthFilter
  12.     If IsNull(Trim(cmbSearchByProcessMonth.Value)) Then
  13.         ShowMessegeBox "לא נרשם תאריך חוקי"
  14.         Exit Sub
  15.     End If
  16.     strMonthFilter = "fldmpsProcessMonth =" & "#" & cmbSearchByProcessMonth.Value & "#"
  17.  
  18.     '--------DepartmentFilter
  19.     If cmbSearchByDepartment.Value = -999 Or IsNull(Trim(cmbSearchByDepartment.Value)) Then
  20.         strDepartmentFilter = ""
  21.     Else
  22.         strDepartmentFilter = "flddipDepartmentCode=" & cmbSearchByDepartment.Value & " AND "
  23.     End If
  24.  
  25.  
  26.     '--------ProjectTypeFilter
  27.     If cmbSearchByProjectTypeCode.Value = -999 Or IsNull(Trim(cmbSearchByProjectTypeCode.Value)) Then
  28.         strProjectTypeFilter = ""
  29.     Else
  30.         strProjectTypeFilter = "flddipProjectTypeCode=" & cmbSearchByProjectTypeCode.Value & " AND "
  31.     End If
  32.  
  33.  
  34.     '--------CustomerFilter
  35.     If cmbSearchByCustomer.Value = -999 Or IsNull(Trim(cmbSearchByCustomer.Value)) Then
  36.         strCustomerFilter = ""
  37.     Else
  38.         strCustomerFilter = "fldcicCustInternaCode=" & cmbSearchByCustomer.Value & " AND "
  39.     End If
  40.  
  41.      '--------ProjectFilter
  42.     If cmbSearchByProject.Value = -999 Or IsNull(Trim(cmbSearchByProject.Value)) Then
  43.         strProjectFilter = ""
  44.     Else
  45.         strProjectFilter = "fldmpsDepartmentProjectCode =" & cmbSearchByProject.Value & " AND "
  46.     End If
  47.  
  48.     '--------InvoiceFilter
  49.     If cmbInvoiceNumber.Value = -10000 Or IsNull(Trim(cmbInvoiceNumber.Value)) Then
  50.         strInvoiceFilter = ""
  51.     Else
  52.         strInvoiceFilter = "fldmpsInvoiceNumber=" & cmbInvoiceNumber.Value & " AND "
  53.     End If
  54.  
  55.     '--------TotalFilter
  56.     strTotalFilter = strDepartmentFilter & strProjectTypeFilter & strCustomerFilter & strProjectFilter & strInvoiceFilter & strMonthFilter
  57.  
  58.     Me.Filter = strTotalFilter  //   Here I Get The Error.
  59.     Me.FilterOn = True
  60. End Sub
-----------------------------------------------------------
I checked The "TotalFilter" and was no problem.?????????
Feb 15 '07 #8

NeoPa
Expert Mod 15k+
P: 31,186
The code mainly seems fine to me if [fldmpsProcessMonth] is a Date/time field and all the other fields are numeric.
There is no point in saying IsNull(Trim()) as that is the same as IsNull().
I've done some minor tidy-ups for you but I haven't fixed anything fundamental as I don't have the field types yet.

What are the types of all the fields?
Expand|Select|Wrap|Line Numbers
  1. Private Sub FilterProcessForm()
  2.  
  3.     Dim strTotalFilter As String
  4.     Dim strMonthFilter As String
  5.     Dim strDepartmentFilter As String
  6.     Dim strProjectTypeFilter As String
  7.     Dim strCustomerFilter As String
  8.     Dim strProjectFilter As String
  9.     Dim strInvoiceFilter As String
  10.  
  11.     '--------MonthFilter
  12.     If IsNull(Me!cmbSearchByProcessMonth) Then
  13.         ShowMessegeBox "?? ???? ????? ????"
  14.         Exit Sub
  15.     End If
  16.     strMonthFilter = "fldmpsProcessMonth=" & "#" & Me!cmbSearchByProcessMonth & "#"
  17.  
  18.     '--------DepartmentFilter
  19.     If Me!cmbSearchByDepartment = -999 Or IsNull(Me!cmbSearchByDepartment) Then
  20.         strDepartmentFilter = ""
  21.     Else
  22.         strDepartmentFilter = "flddipDepartmentCode=" & Me!cmbSearchByDepartment & " AND "
  23.     End If
  24.  
  25.  
  26.     '--------ProjectTypeFilter
  27.     If Me!cmbSearchByProjectTypeCode = -999 Or IsNull(Me!cmbSearchByProjectTypeCode) Then
  28.         strProjectTypeFilter = ""
  29.     Else
  30.         strProjectTypeFilter = "flddipProjectTypeCode=" & Me!cmbSearchByProjectTypeCode & " AND "
  31.     End If
  32.  
  33.  
  34.     '--------CustomerFilter
  35.     If Me!cmbSearchByCustomer = -999 Or IsNull(Me!cmbSearchByCustomer) Then
  36.         strCustomerFilter = ""
  37.     Else
  38.         strCustomerFilter = "fldcicCustInternaCode=" & Me!cmbSearchByCustomer & " AND "
  39.     End If
  40.  
  41.      '--------ProjectFilter
  42.     If Me!cmbSearchByProject = -999 Or IsNull(Me!cmbSearchByProject) Then
  43.         strProjectFilter = ""
  44.     Else
  45.         strProjectFilter = "fldmpsDepartmentProjectCode=" & Me!cmbSearchByProject & " AND "
  46.     End If
  47.  
  48.     '--------InvoiceFilter
  49.     If Me!cmbInvoiceNumber = -10000 Or IsNull(Me!cmbInvoiceNumber) Then
  50.         strInvoiceFilter = ""
  51.     Else
  52.         strInvoiceFilter = "fldmpsInvoiceNumber=" & Me!cmbInvoiceNumber & " AND "
  53.     End If
  54.  
  55.     '--------TotalFilter
  56.     strTotalFilter = strDepartmentFilter & _
  57.                      strProjectTypeFilter & _
  58.                      strCustomerFilter & _
  59.                      strProjectFilter & _
  60.                      strInvoiceFilter & _
  61.                      strMonthFilter
  62.  
  63.     Me.Filter = strTotalFilter  //   Here I Get The Error.
  64.     Me.FilterOn = True
  65. End Sub
Feb 15 '07 #9

P: 16
Thanks a lot for your kind help.
All the variables are int, beside the ProcessMonth which is DateTime
It' s the third form I do with few combos that are filtering together the form' and never got such error. pls help.
Feb 18 '07 #10

NeoPa
Expert Mod 15k+
P: 31,186
In that case try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub FilterProcessForm()
  2.  
  3.     Dim strFilter As String
  4.  
  5.     '--------MonthFilter
  6.     If IsNull(Me!cmbSearchByProcessMonth) Then
  7.         ShowMessegeBox "?? ???? ????? ????"
  8.         Exit Sub
  9.     End If
  10.  
  11.     strFilter = "(fldmpsProcessMonth=" & _
  12.                 Format(Me!cmbSearchByProcessMonth,'\#m/d/yyyy\#)')
  13.  
  14.     '--------DepartmentFilter
  15.     If Nz(Me!cmbSearchByDepartment,-999) <> -999 Then _
  16.         strFilter = strFilter & " AND (" & _
  17.                 "flddipDepartmentCode=" & Me!cmbSearchByDepartment & ")"
  18.  
  19.     '--------ProjectTypeFilter
  20.     If Nz(Me!cmbSearchByProjectTypeCode,-999) = -999 Then _
  21.         strFilter = strFilter & " AND (" & _
  22.                 "flddipProjectTypeCode=" & Me!cmbSearchByProjectTypeCode & ")"
  23.  
  24.     '--------CustomerFilter
  25.     If Nz(Me!cmbSearchByCustomer,-999) <> -999 Then _
  26.         strFilter = strFilter & " AND (" & _
  27.                 "fldcicCustInternaCode=" & Me!cmbSearchByCustomer & ")"
  28.  
  29.      '--------ProjectFilter
  30.     If Nz(Me!cmbSearchByProject,-999) <> -999 Then _
  31.         strFilter = strFilter & " AND (" & _
  32.                 "fldmpsDepartmentProjectCode=" & Me!cmbSearchByProject & ")"
  33.  
  34.     '--------InvoiceFilter
  35.     If Nz(Me!cmbInvoiceNumber,-10000) <> -10000 Then _
  36.         strFilter = strFilter & " AND (" & _
  37.                 "fldmpsInvoiceNumber=" & Me!cmbInvoiceNumber & ")"
  38.  
  39.  
  40.     Me.Filter = strFilter
  41.     Me.FilterOn = True
  42. End Sub
Feb 18 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.