Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2004
    Posts
    40

    Unanswered: how to pause it when open the form ?

    When i open the form, it list out all the records in database immediately.

    How i able to write additional code to stop listing out all the records in form, And when i input both txt box, it will list out the limit range numbers.

    My present code is here.

    Private Sub cmdrange_Click()
    On Error GoTo Err_cmdrange_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Qrylist subform"
    stLinkCriteria = "[JOB NO] Between '" & Me![txtfirstlist] & "' AND '" & Me![txtlastlist] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdrange_Click:
    Exit Sub

    Err_cmdrange_Click:
    MsgBox Err.Description
    Resume Exit_cmdrange_Click

    End Sub

    Please help.

    Thanks

  2. #2
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    As I can to foresee from your code, it is a SUBFORM. If
    it's so;
    Open MAIN FORM in design view, click on the margin of the
    SUBFORM, open properties box, fill up LINK CHILD FIELDS and LINK MASTER FIELDS properties.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    using BETWEEN on a TEXT field may not be doing what you think it is...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    The original question was:
    When i open the form, it list out all the records in database immediately.

    How i able to write additional code to stop listing out all the records in form
    A quick way to do that is to add this code:
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
        Me.Filter = "PartID = 0"
        Me.FilterOn = True
    End Sub
    Replace PartID with your key field (and this assumes you don't have a key value = 0).

    Then, have the code that is supposed to show records include this line:
    Code:
    Me.FilterOn = False
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  5. #5
    Join Date
    Jun 2004
    Posts
    40
    Hi. Thanks for rely.

    Assume i should write this code although i have little experience programming vba.

    Private Sub cmdrange_Click()
    On Error GoTo Err_cmdrange_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Qrylist subform"
    stLinkCriteria = "[JOB NO] Between '" & Me![txtfirstlist] & "' AND '" & Me![txtlastlist] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Me.Filter = "[JOB NO] = 0"
    Me.FilterOn = True

    Exit_cmdrange_Click:
    Exit Sub

    Err_cmdrange_Click:
    MsgBox Err.Description
    Resume Exit_cmdrange_Click

    End Sub

    however it doesn work.


    Quote Originally Posted by tcace
    The original question was:

    A quick way to do that is to add this code:
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
        Me.Filter = "PartID = 0"
        Me.FilterOn = True
    End Sub
    Replace PartID with your key field (and this assumes you don't have a key value = 0).

    Then, have the code that is supposed to show records include this line:
    Code:
    Me.FilterOn = False

  6. #6
    Join Date
    Jun 2004
    Posts
    40
    hi mstef_Zg, thanks for rely.

    Actually it is not sub form. Normally i will do the form wizard to do for us with abit of modifying the code for list range function. I use the "detail" form to design to list out the records. But i have not know the code how to stop the listing out all the records when i open this form from the switchboard. Only when a person input the specific number to limit the records, it will list out.

    It is not sense when a person open the form, it immediately list out everything without input anything at all. -_- ...

  7. #7
    Join Date
    Feb 2004
    Posts
    34
    Tcase gave you the answer. If you add a filter to the recordsource of the form that will give as result 0 records it prevents all records from being shown upon opening the form. Then after input of the start and end order ID's and clicking the button you can change the filter to the desired values. However as Teddy says a textfield behaves differently from numeric fields when using ORDER BY or BETWEEN:

    Text columns containing the values 1, 2 and 10 are sorted:

    1
    10
    2

    Numeric columns containing the values 1, 2 and 10 are sorted:

    1
    2
    10

    So make sure to choose the proper fieldtype in your tables

  8. #8
    Join Date
    Jun 2004
    Posts
    40
    Teddy, thank for rely.

    i know that it behavely funny.

    Actually from what i have learning from ms access first time, i realised that i can`t input number like " 05/001 " , 05 stand for year, 001 stand for paper number " for this field, number type.

    So i instead change to text type. so that i can input 05/001 for filter purpose.

    To answer your question further, i usually fix this by choosing accelerating and decreasing from textbox property in wizard function

    it should be ok ,

    But i very much welcome the comments so that i can improve better.

    cheer.
    Last edited by xeroleacy; 10-16-05 at 21:45.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •