сделать пользовательский фильтр

beteem
Дата: 17.12.2011 00:42:23
добрый день форумчане
есть вопрос, очень срочно нужно решить, искал, нигде не нашел.
есть таблица, куда вводятся происшествия соследующими полями
Сотрудник, Что случилось, Когда случилось
так вот, нужно сделать форму, чтобы там былы 2 поля, куда можно было бы ввести дату "От" и "До", кнопка искать и отчет фильтруется таким образом.
я до этого делал следующим образом:

Private Sub Кнопка4_Click()
On Error GoTo Err_Кнопка4_Click

Dim stDocName As String

DoCmd.OpenReport "mainreport", acPreview, , "[sotrudniki.fio]='" & ПолеСоСписком2.Value & "'"

Exit_Кнопка4_Click:
Exit Sub

Err_Кнопка4_Click:
MsgBox Err.Description
Resume Exit_Кнопка4_Click

End Sub

это позволяло передавать значение из ComboBox по кнопке в фильтр.
очень прошу помочь.
Заранее благодарен Всем
qwerty112
Дата: 17.12.2011 01:01:24
beteem
я до этого делал следующим образом:
    DoCmd.OpenReport "mainreport", acPreview, , "[sotrudniki.fio]='" & ПолеСоСписком2.Value & "'"

это позволяло ...

и шо, правда позволяло ??
sdku
Дата: 17.12.2011 01:14:44
beteem
...чтобы там былы 2 поля, куда можно было бы ввести дату "От" и "До"
   DoCmd.OpenReport "mainreport", acPreview, , "[sotrudniki.fio]='" & ПолеСоСписком2.Value & "'"
точка в имени поля -это круто
речь идет о двух полях-[fio]>"от" and [fio]<"до"
beteem
Дата: 17.12.2011 01:16:42
sdku
beteem
...чтобы там былы 2 поля, куда можно было бы ввести дату "От" и "До"
   DoCmd.OpenReport "mainreport", acPreview, , "[sotrudniki.fio]='" & ПолеСоСписком2.Value & "'"
точка в имени поля -это круто
речь идет о двух полях-[fio]>"от" and [fio]<"до"

это точка не мною как бы поставлена. тут получается таблица sotrudniki и поле фиою так шифрует, по крайней мере, у меня.
мне нужно тут как бы вставить 2 условия. первый поле дата больше, и второй, поле дата - меньше
alvk
Дата: 17.12.2011 04:45:27
beteem,

beteem
это точка не мною как бы поставлена

вам уже сказали, что у вас неправильно, чего вы тут такое пишите? кем она поставлена? исправляйте. а условия вставляйте через and
beteem
Дата: 17.12.2011 13:50:17
alvk
beteem,

beteem
это точка не мною как бы поставлена

вам уже сказали, что у вас неправильно, чего вы тут такое пишите? кем она поставлена? исправляйте. а условия вставляйте через and


можете написать исправленный кусок кода? буду очень благодарен. на счет and - можете дать ссылку на пример использования, или вставить тут кусок кода с примером?
alvk
Дата: 17.12.2011 17:52:20
beteem,

stLinkCriteria = "[дата]<= #" & Format(Me.до, "mm\/dd\/yy") & "#" & " And  " & "[дата]>= #" & Format(Me.от, "mm\/dd\/yy") & "#"

при условии, что на форме есть поля "от" и "до"
PMVolga
Дата: 18.12.2011 20:39:09
Читаем справку и делаем, как там написано:
Access Developer Reference
Application.BuildCriteria Method
Show All
Hide All
The BuildCriteria method returns a parsed criteria string as it would appear in the query design grid (design grid: The grid that you use to design a query or filter in query Design view or in the Advanced Filter/Sort window. For queries, this grid was formerly known as the QBE grid.), in Filter By Form (Filter By Form: A technique for filtering data that uses a version of the current form or datasheet with empty fields in which you can type the values that you want the filtered records to contain.) or Server Filter By Form (Server Filter By Form: A technique that uses a version of the current form or datasheet with empty fields in which you can type values you want the filtered records to contain. The data is filtered by the server before it's retrieved from the database.) mode. For example, you may want to set a form's Filter or ServerFilter property based on varying criteria from the user. You can use the BuildCriteria method to construct the string expression argument for the Filter or ServerFilter property. String.
Syntax

expression.BuildCriteria(Field, FieldType, Expression)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
Field Required String The field for which you wish to define criteria.
FieldType Required Integer An intrinsic constant (intrinsic constant: A constant that is supplied by Access, VBA, ADO, or DAO. These constants are available in the Object Browser by clicking globals in each of these libraries.) denoting the data type of the field. Can be set to one of the DAO DataTypeEnum values.
Expression Required String A string expression identifying the criteria to be parsed.

Return Value
String

Remarks


The BuildCriteria method enables you to easily construct criteria for a filter based on user input. It parses the expression argument in the same way that the expression would be parsed had it been entered in the query design grid, in Filter By Form or Server Filter By Form mode.

For example, a user creating a query on an Orders table might restrict the result set (result set: The set of records that results from running a query or applying a filter.) to orders placed after January 1, 1995, by setting criteria on an OrderDate field. The user might enter an expression such as the following one in the Criteria row beneath the OrderDate field:

>1-1-95

Microsoft Access automatically parses this expression and returns the following expression:

>#1/1/95#

The BuildCriteria method provides the same parsing from Visual Basic code. For example, to return the preceding correctly parsed string, you can supply the following arguments to the BuildCriteria method:

Dim strCriteria As String
strCriteria = BuildCriteria("OrderDate", dbDate, ">1-1-95")

Since you need to supply criteria for the Filter property in correctly parsed form, you can use the BuildCriteria method to construct a correctly parsed string.

You can use the BuildCriteria method to construct a string with multiple criteria if those criteria refer to the same field. For example, you can use the BuildCriteria method with the following arguments to construct a string with multiple criteria relating to the OrderDate field:

strCriteria = BuildCriteria("OrderDate", dbDate, ">1-1-95 and <5-1-95")

This example returns the following criteria string:

OrderDate>#1/1/95# And OrderDate<#5/1/95#

However, if you wish to construct a criteria string that refers to multiple fields, you must create the strings and concatenate them yourself. For example, if you wish to construct criteria for a filter to show records for orders placed after 1-1-95 and for which freight is less than $50, you would need to use the BuildCriteria method twice and concatenate the resulting strings.


Example


The following example prompts the user to enter the first few letters of a product's name and then uses the BuildCriteria method to construct a criteria string based on the user's input. Next, the procedure provides this string as an argument to the Filter property of a Products form. Finally, the FilterOn property is set to apply the filter.

Visual Basic for Applications
Sub SetFilter()
Dim frm As Form, strMsg As String
Dim strInput As String, strFilter As String

' Open Products form in Form view.
DoCmd.OpenForm "Products"
' Return Form object variable pointing to Products form.
Set frm = Forms!Products
strMsg = "Enter one or more letters of product name " _
& "followed by an asterisk."
' Prompt user for input.
strInput = InputBox(strMsg)
' Build criteria string.
strFilter = BuildCriteria("ProductName", dbText, strInput)
' Set Filter property to apply filter.
frm.Filter = strFilter
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True
End Sub
alvk
Дата: 19.12.2011 07:05:36
PMVolga,

Это где такая справка? У меня такая:
Программист-Любитель
Дата: 19.12.2011 08:43:53
alvk
Это где такая справка? У меня такая:

В гугле забанили ?