Command button to change my form's dataset

J

Joseph Ellis

Hello all,

I have a church directory database which contains information about
both current and past church members. I've made a form which displays
all the records in the table (that is, none are filtered out yet).

I'd like to put a button on the form that when pressed would cause the
form to display information of current members only.

The field that designates whether a person is "current" or not is
called "Retired", and is in a table called "Households".

I assume that I'd use the On Click event to do this, but that's where
I'm stuck. What do I need to enter there to make the form display
only those records in which Retired = False?

Or is there a better way to do it?

Thanks,
Joseph
 
V

Van T. Dinh

****Untested****
Private Sub cmdCurrent_Click()
Me.Filter = "[Retired] = False"
Me.FilterOn = True
End Sub
 
J

Joseph Ellis

****Untested****
Private Sub cmdCurrent_Click()
Me.Filter = "[Retired] = False"
Me.FilterOn = True
End Sub

Thanks Van,

I had actually figured that out and was going to post my code. I also
modified it a little so as to become a toggle button to switch between
All or Current records:

Private Sub cmdCurrentToggle_Click()
Me.Filter = "[retired] = 0"
If Me.FilterOn Then
Me.FilterOn = False
Else
Me.FilterOn = True
End If
End Sub

It works, and is the first bit of VB (This IS VB, isn't it?) code I've
ever done. Go me.

Thanks,
Joseph
 
J

Joseph Ellis

Thanks Van,

I had actually figured that out and was going to post my code. I also
modified it a little so as to become a toggle button to switch between
All or Current records:

Private Sub cmdCurrentToggle_Click()
Me.Filter = "[retired] = 0"
If Me.FilterOn Then
Me.FilterOn = False
Else
Me.FilterOn = True
End If
End Sub

It works, and is the first bit of VB (This IS VB, isn't it?) code I've
ever done. Go me.

Thanks,
Joseph

BTW, what is Me? I assume that it refers to the form, but it would
seem more intuitive to me for Me to refer to the command button.

Just wondering.
 
V

Van T. Dinh

Me refers to the current Access Object according to the current context of
the code. In this case, the Sub is in the CBF (Code-Behind-Form) module
belonging to your Form (an Access Object). Thus Me refers to your current
Form.

There is a CurrentControl Object that refers to your current Control.

--
HTH
Van T. Dinh
MVP (Access)


Joseph Ellis said:
Thanks Van,

I had actually figured that out and was going to post my code. I also
modified it a little so as to become a toggle button to switch between
All or Current records:

Private Sub cmdCurrentToggle_Click()
Me.Filter = "[retired] = 0"
If Me.FilterOn Then
Me.FilterOn = False
Else
Me.FilterOn = True
End If
End Sub

It works, and is the first bit of VB (This IS VB, isn't it?) code I've
ever done. Go me.

Thanks,
Joseph

BTW, what is Me? I assume that it refers to the form, but it would
seem more intuitive to me for Me to refer to the command button.

Just wondering.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top