Access solves the problem that the combo box cannot meet the needs of a large amount of data.

Source: Internet
Author: User
Problem: Access has a combo box that allows you to quickly select the required data from multiple rows of records. But what if the record exceeds? It is very inconvenient to select. What should I do? A: In fact, a lot of data can be classified (stratified), and we can pre-filter data. In the following example

Problem: There is a combination box in Access to quickly select the required data from multiple rows of records. But what if the record exceeds? It is very inconvenient to select. What should I do? A: In fact, a lot of data can be classified (stratified), and we can pre-filter data. In the following example

Problem:

Access has CombinationBox to quickly select the required Data. But what if the record exceeds? It is very inconvenient to select. What should I do?

Answer:

Actually many DataCan be selected by category (stratified), and we can pre-filter Data.

In the following example, the same form class is repeatedly opened for multiple layers. Data.

Of course, pre-screening is also included. DataFunction.

Now start:

1. Create a form (testForm) with a text box (text0) and a button (Command2 ).

2. Create a form (selectForm) with a list box (list0 ).

3. In the "updated" event of the text box in testForm, write the following code to open the selectForm (selectForm), and the row source (RowSource) of the list box (list0) assign values.

Private Sub Text0_AfterUpdate ()

DoCmd. OpenForm "selectform"

'This line of code implements fuzzy search for the BTYPE table, using the LIKE keyword in the WHERE clause for wildcard

Forms ("selectform "). list0.RowSource = "SELECT btype. soncount, btype. userCode, btype. fullName, btype. typeId FROM btype WHERE btype. fullname like '* "& Text0.Value &"*'"

End Sub

4. In the "click" event of the command button in testForm, write the following code to open the product name selection form and search by category.

5. Then, enter the following code in testForm to open the form itself multiple times and display the subclass. Data.

To make code reuse, two general processes are written.

Option Compare Database

Dim f

Private Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)

'Set the "Key preview" attribute of the form to "yes" first"

'The process will speed up your input.

'If you press the ESCAPE key, close the form.

If KeyCode = vbKeyEscape Then

CloseAllSelectForm "SelectForm"

End If

End Sub

Private Sub List0_DblClick (Cancel As Integer)

CheckYouSelect

End Sub

Private Sub List0_KeyPress (KeyAscii As Integer)

'The entire keyboard operation is implemented in this process.

If KeyAscii = 13 Then

CheckYouSelect

End If

End Sub

Sub closeAllSelectForm (strFormName As String)

'General process 1

'This process is used to close all the forms with the specified name

For Each objForm In Forms

If objForm. Name = strFormName Then

DoCmd. Close acForm, objForm. Name

End If

Next objForm

End Sub

Sub checkYouSelect ()

'General process 2

'Check your selection

'If the suncount column is 0 (it indicates there is no next layer)

'You can put the selected product name in the text box.

On Error Resume Next

Set f = New Form_SelectForm

Dim objForm As Form

If List0.Column (0) = 0 Then

Forms ("testform"). Text0.Value = List0.Column (2)

CloseAllSelectForm "SelectForm"

Else

F. Visible = True

F. List0.RowSource = "SELECT btype. soncount, btype. UserCode, btype. FullName, btype. typeId FROM btype WHERE parid = '" & List0.Value &"'"

End If

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.