Visual Data Selection for a Query(Access)

download Visual Data Selection for a Query(Access)

of 9

Transcript of Visual Data Selection for a Query(Access)

  • 8/13/2019 Visual Data Selection for a Query(Access)

    1/9

    Visual Data Selection For a Query

    The main purpose of data filtering consists of selecting records. As you knowalready, records are stored in tables but they can be identified by the columns of a table.Therefore, before filtering records, you must first specify the columns that would be inoled

    in your filtering.

    !f you are creating a "uery using the wi#ard, first select a table $or an already created "uery%&

    After specifying the table $or "uery% that holds the records, to select a column, in the Aailable Fields

    list, you can double'click the desired column$s%&

    http://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htm
  • 8/13/2019 Visual Data Selection for a Query(Access)

    2/9

    The techni"ue of selecting the fields is the same applied when creating a table using the Table (i#ard.

    !f you are creating a "uery in the DesignView, when you are presented with the Show Tabledialog bo), to select a table, you can click it and click the Add button, or you can double'click thetable&

    http://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htm
  • 8/13/2019 Visual Data Selection for a Query(Access)

    3/9

    !f you hae already selected a table and want to change it or want to add a table $or "uery%, you can

    right'click the Select Query window and click Add Table. After specifying the table, to select a

    column, you can drag it from the table and drop it in a column in the lower section of the window&

    !nstead of adding one column at a time, you can select more than one column using the *trl or the

    Shift keys and dragging the selection to a column in the lower section of the window. To include all

    columns in a "uery, drag the + field and drop it in the bottom section.

    ractical -earning& Selecting Fields For a Query

    . !n the Sample Fields, double'click First/ame, -ast/ame, Date0ired,Salary,!s1arried, and !sATeacher&

    http://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htm
  • 8/13/2019 Visual Data Selection for a Query(Access)

    4/9

    2. *lick /e)t. !f you are asked whether you want a detail or a summary "uery, make sure the first

    radiobutton is selected and click /e)t3. *hange the Title to StaffSocialInformationand click Finish

    4. (hile the "uery window is selected and displaying, on the Query Datasheet toolbar, click /ew

    5b6ect& AutoForm to generate a form

    7. *lose the form8. (hen asked whether you want to sae it, click 9es

    :. Accept the suggested name as StaffSocialInformationand click 5;

  • 8/13/2019 Visual Data Selection for a Query(Access)

    5/9

    saing the "uery, to iew its statement, open the "uery in design iew, right'click its window, and

    click SQ- View. 9ou can also access the SQ- View option from the main menu under View.

    To select eerything from a table, you can use the asterisk as the range of alues. For e)ample, to

    select all records, you would use a the statement as follows&

    SELECT * FROM Students;

    This e)ample would select all records from a table named Students. As opposed to selecting all

    records, you can select one particular column whose fields you want to iew. To do this, you can

    replace the Whatfactor in the synta) with the name of the desired column. 0ere is an e)ample&

    SELECT LastName FROM Students;

    This statement would select only the column that contains the last names. To consider more than one

    column in a statement, you can list them in the Whatfactor of our synta), separating them with acomma e)cept for the last column. The synta) to use is&

    SELECTColumn1, Column2, Column_nFROMWhatObject;

    As an e)ample, to select the names, gender, and home phone of records from a table called Students,

    you would the following statement&

    SELECT FirstName, LastName, Gender, HomePhoneFROM Students

    As mentioned earlier, to programmatically create a "uery, you can pass the SQ- statement as thesecond argument of the CreateQueryDef()method. 0ere is an e)ample that uses the

    Microsoft Access-ibrary&Private Sub mdCreate!uer"#C$i%&' (im ur(atabase )s Obet (im +r"Em$o"ees )s Obet

    (im strStatement )s Strin-

    . Get a re/erene to the urrent database Set ur(atabase 0 Current(b

    strStatement 0 1SELECT (ateHired, FirstName, 1 2 # 1LastName, (eartment FROM Em$o"ees;1

    . Create a ne3 +uer" named Em$o"ees4n/o Set +r"Em$o"ees 0 ur(atabase5Create!uer"(e/&1Em$o"ees4n/o1, strStatement'

    End Sub

    9ou can use the same approach with DA5.

    ractical -earning& Viewing a SQ- Statement From a Query

    . !n the Database window, click Queries

    2. !n the Queries section, double'click StaffSocialInformation

    3. To iew its SQ- statement, right'click its title bar and click SQ- View

    http://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htm
  • 8/13/2019 Visual Data Selection for a Query(Access)

    6/9

    4. To switch it to Design View, right'click its Title ar and click Query Design

    7. *lose the Select Query window. !f asked whether you want to sae the change, click /o

    Data Selection For a Form

    As mentioned preiously, after creating and saing a "uery, you can use it a datasourcefor a form. !nstead of primarily creating a "uery, you can either type a SQ- statementin the ?ecord Source property or use its ellipsis button to create a "uery. Berything is done as seen

    aboe.

    ractical -earning& Selecting Data for a Form

    . !n the Database window, click Forms and double'click *reate Form !n Design View

    2. !n the roperties window, click the ?ecord Source field to reeal its ellipsis button and click

    that ellipsis button

    3. !n the Show Table dialog bo), click Students, click Add, and click *lose

    4. !n the list of fields, click First/ame, press and hold *trl

    7. !n the list of fields, click -ast/ame, arents/ames, Bmergency/ame, and Bmergencyhone

    8. ?elease *trl

    :. Drag one of the selected items and drop in the first empty field in the lower section of the

    window&

    http://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htmhttp://www.functionx.com/vbaccess/Lesson15b.htm
  • 8/13/2019 Visual Data Selection for a Query(Access)

    7/9

    . Display the Field -ist of the form and notice that its title bar displays a SQ- statement. Also notice that the ?ecord Source of the form is made of a SQ- statement

  • 8/13/2019 Visual Data Selection for a Query(Access)

    8/9

    2. Sae the form as StudentsContactInformation

    3. Drag the fields from the Field -ist to drop them on the form and design it as follows&

    4. ?ight'click the form and click Form 0eaderCFooter7. @sing the *ommand utton (i#ard, add a button named cmd*lose and labeled *lose that

    would be used to close the form

  • 8/13/2019 Visual Data Selection for a Query(Access)

    9/9

    8. Sae and close the form

    reious *opyright 2>>7 FunctionE, !nc. /e)t

    http://www.functionx.com/vbaccess/Lesson15.htmhttp://www.functionx.com/vbaccess/index.htmhttp://www.functionx.com/vbaccess/Lesson15c.htmhttp://www.functionx.com/vbaccess/Lesson15.htmhttp://www.functionx.com/vbaccess/index.htmhttp://www.functionx.com/vbaccess/Lesson15c.htm