change datasource for grid on timer event

Posted on 2007-10-01
Last Modified: 2008-01-09
I have a form that has a gridview on it.  I would like to have a timer event that fills the datagrid with dataset1 and then on timer next fire would fill datagrid with dataset2
Here is the code that I used in access for this same procedure...

Static B As Boolean
If B Then [Forms]![myform1].Form.RecordSource = "rs" Else [Forms]![myform1].Form.RecordSource = "rs2"
B = Not B
Question by:H-SC
    LVL 8

    Accepted Solution


    put a timer control on the form, and on it's event, use this code, which myDataSet, myDataSet2 are public variables, created before.


    dim b as boolean

    if b then
       myGrid.datasource = myDataSet
       myGrid.datamember = "myTable"
       myGrid.datasource = myDataSet2
       myGrid.datamember = "myTable2"
    end if
    b = not b


    LVL 8

    Expert Comment

    oops, it should be

    static b as boolean

    instead of

    dim b as boolean
    LVL 1

    Author Comment


    many thanks for the response... this works perfect!!  Also if I wanted to apply this same code to the datasource of a form, how would that look?
    LVL 8

    Expert Comment

    you're welcome =)

    a form doesn't have a datasource, but I think you mean datasource of a grid on another form, than the code will simply be;


    LVL 1

    Author Comment

    sounds great rob....many thanks again

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now