Command button to change my form's dataset

  • Thread starter Thread starter Joseph Ellis
  • Start date Start date
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
 
****Untested****
Private Sub cmdCurrent_Click()
Me.Filter = "[Retired] = False"
Me.FilterOn = True
End Sub
 
****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
 
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.
 
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.
 
Back
Top