change datasource for grid on timer event

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
LVL 1
H-SCAsked:
Who is Participating?
 
MrRobotConnect With a Mentor Commented:
hi,

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"
else
   myGrid.datasource = myDataSet2
   myGrid.datamember = "myTable2"
end if
b = not b

****

rob
0
 
MrRobotCommented:
oops, it should be

static b as boolean

instead of

dim b as boolean
0
 
H-SCAuthor Commented:
rob,

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?
0
 
MrRobotCommented:
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;

myForm.myGrid.datasource

0
 
H-SCAuthor Commented:
sounds great rob....many thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.