Enable/Disable Button on DS Subform Record Selection, HELP?

G

Guest

Hi all,
I have three delete buttons on main form that I would like to have them sit
of on top of each other.

I have 2 subforms in Datasheet view on a main form. Btn1 for deleting the
whole record on the form, Btn2 for delecting a selected/higlighted record in
the first subform and finally Btn3 for deleting a selected record in the
sencond subform. I have figured out a way to Delete the Selected Record using
their respective buttons.
Eg: first button has got this SQL string to delete straight from table and
that works..

But what I want to do is to have appropirate buttons being either enabled or
visible when a record is selected in a respective subform of if none is
selected then, the Btn1 which does the whole delete should be enabled/visible.
I used the on current Event off all the 3 forms with the code below but its
im not getting the hehaviour I want...

Me.Parent!btnDeletePlantingDetails.Enabled = True
Me.Parent!btnDeletePlanting.Enabled = False
Me.Parent!btnDeleteFertDetails.Enabled = False

I just want the respective button to show up when i select a record to be
deleted on a subform on a certain subform...

Thanks for any help
 
W

Wolfgang Kais

Hello "niuginikiwi".

niuginikiwi said:
Hi all,
I have three delete buttons on main form that I would like to have
them sit of on top of each other.

I have 2 subforms in Datasheet view on a main form. Btn1 for
deleting the whole record on the form, Btn2 for delecting a
selected/higlighted record in the first subform and finally Btn3
for deleting a selected record in the sencond subform. I have
figured out a way to Delete the Selected Record using their
respective buttons.
Eg: first button has got this SQL string to delete straight from
table and that works..

How about a single delete button and
On Error Resume Next
Screen.PreviosControl.SetFocus
RunCommand acCmdDeleteRecord
But what I want to do is to have appropirate buttons being either
enabled or visible when a record is selected in a respective subform
of if none is selected then, the Btn1 which does the whole delete
should be enabled/visible. I used the on current Event off all the 3
forms with the code below but its im not getting the hehaviour I want...

Me.Parent!btnDeletePlantingDetails.Enabled = True
Me.Parent!btnDeletePlanting.Enabled = False
Me.Parent!btnDeleteFertDetails.Enabled = False

The last subforms delete button will be enabled although the focus
sits in the main form.
I just want the respective button to show up when i select a record
to be deleted on a subform on a certain subform...

You do not have to write code in the subforms to achieve this.
In design view, enable btnDeletePlanting and disable the other two.
Write code for the Enter and Exit events of the two subform
controls in the main form (I assumed that the names of these
controls are fsubPlantingDetails and fsubFertDetails):

Private Sub fsubPlantingDetails_Enter()
Me.btnDeletePlanting.Enabled = False
Me.btnDeletePlantingDetails.Enabled = True
End Sub

Private Sub fsubPlantingDetails_Exit(Cancel As Integer)
Me.btnDeletePlantingDetails.Enabled = False
Me.btnDeletePlanting.Enabled = True
End Sub

Private Sub fsubFertDetails_Enter()
Me.btnDeletePlanting.Enabled = False
Me.btnDeleteFertDetails.Enabled = True
End Sub

Private Sub fsubFertDetails_Exit(Cancel As Integer)
Me.btnDeleteFertDetails.Enabled = False
Me.btnDeletePlanting.Enabled = True
End Sub
 
G

Guest

Thanks Wolfgang,
I preferred your first option which is having the one button to do all with
the piece of code you gave me sorted me out exactly with what I was looking
for....
Thanks so much
 

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