Results 1 to 4 of 4

Thread: [RESOLVED] [Access 2003] Form Data Source

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [RESOLVED] [Access 2003] Form Data Source

    I have a form on which I have a header and a detail section, the default view is set to Continuous Forms and the Data Soruce is set to a Query.

    In my detail section I have some fields from the query, so that I get to see all entries of the query in the form.

    In my header I have three fields, Date, Action and User.

    How can I use the contents of these fields to limit the results shown.

    i.e. The query is filtered on the relevant fields.
    Signature Under Construction

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [Access 2003] Form Data Source

    Off the top of my head I would say you could limit what is shown by specifiying a specific date, a specific action and and specific user.

    If you specify all three, it should be really, really limited, so perhaps only specifiying two, or even one, would give you good results.

  3. #3
    Hyperactive Member Davadvice's Avatar
    Join Date
    Apr 2007
    Location
    Glasgow (Scotland)
    Posts
    440

    Re: [Access 2003] Form Data Source

    hi Torc,

    You could use a query def and re-write the source query dependant on the filters you apply.

    say you have a customer name then you can say select * from tblCustomer where CusomerId = 1

    i aint used the querydef object in a while but if you use the help in access it gives an example that you should be able to apply. you will have to use the requery function on the form after you have changed the query.

    i'm not sure if you can actualy change the rowsource of a form at runtime but this may be an easier way to do it. all you would have to do is set the form rowsource to the sql you wich to apply and then refresh the form.

    I aint in work just now so don't have access opened and am unable to test sorry.

    good luck

    David
    This is Blank

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: [Access 2003] Form Data Source

    Hi Hack,

    My data source has a total of five fields, Date, Action, User, IDCode and Value.
    My form needed to display the list of IDCode and Value entries for Date,
    Action and User, I could have 1 to 20 entries with different IDCodes.

    Hi Davadvice,

    Many thanks for the advice, I was able to test the following code which works, will now be able to adapt my real code..

    Code:
    Sub ReQuery()
    Dim QuerySqlStr As String
        QuerySqlStr = "SELECT Table1.Date, Table1.User, Table1.Results, Table1.Value " & _
                        "FROM Table1 " & _
                        "WHERE Table1.Date=#" & Format(Form_Form1.TxtDate.Value, "yyyy/mm/dd") & "# AND Table1.User='" & Form_Form1.TxtName.Value & "'"
    
        CurrentDb.QueryDefs.Delete "Query1"
        CurrentDb.CreateQueryDef "Query1", QuerySqlStr
        
        Form_Form1.LblQuery.Caption = QuerySqlStr
        Form_Form1.RecordSource = QuerySqlStr
    End Sub
    Signature Under Construction

Posting Permissions

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



Click Here to Expand Forum to Full Width