Backcolor of field

G

Guest

I have used conditional formatting to change the backcolor of a subform's
record when the record has been selected. I need to return (in code) the
value of the backcolor of the field [lng_ID] in the subform[Sub_Equipment]? I
have tried:
Color = [Forms]![Frm_Edit]![Sub_Equipment]![lng_ID].Backcolor but I get the
error message: Object doesn't support this property or method. Is there any
way of doing this? Thanks!
 
G

Graham Mandeno

Hi Greg

Your expression appears to be correct, although it would be better to add a
".Form" after the subform control name.

Try to add to it bit by bit in the debug window. Try this:
?[Forms]![Frm_Edit].Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Form.Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Form![lng_ID].Name

HOWEVER, I don't think any of this will solve your problem because I'm sure
that conditional formatting does not work by changing the BackColor property
of the control. I think you will always get the BackColor that was set in
design view, no matter which record you are on.
 
G

Guest

Hi Graham, Thanks for your suggestions. Unfortunately it looks like that
property isn't supported. What I am trying to do is find some way to check if
a record has been selected in a subform. My plan was to use conditional
formating to highlight the selected record then check if the backcolor had
changed. If the backcolor had changed, the record would be deleted when I
clicked my deleterecord button. The problem I am having is, that even though
I have not selected a record in the subform, the first record in the subform
gets deleted when I click my deleterecord button. Can you think of any way
around this? Thanks Again, Greg

Graham Mandeno said:
Hi Greg

Your expression appears to be correct, although it would be better to add a
".Form" after the subform control name.

Try to add to it bit by bit in the debug window. Try this:
?[Forms]![Frm_Edit].Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Form.Name
then:
?[Forms]![Frm_Edit]![Sub_Equipment].Form![lng_ID].Name

HOWEVER, I don't think any of this will solve your problem because I'm sure
that conditional formatting does not work by changing the BackColor property
of the control. I think you will always get the BackColor that was set in
design view, no matter which record you are on.
--

Graham Mandeno [Access MVP]
Auckland, New Zealand



Greg said:
I have used conditional formatting to change the backcolor of a subform's
record when the record has been selected. I need to return (in code) the
value of the backcolor of the field [lng_ID] in the
subform[Sub_Equipment]? I
have tried:
Color = [Forms]![Frm_Edit]![Sub_Equipment]![lng_ID].Backcolor but I get
the
error message: Object doesn't support this property or method. Is there
any
way of doing this? Thanks!
 
G

Graham Mandeno

Hi Greg

Can you please post the code for your delete button?

You can tell if a form has a record selected by checking its SelHeight
property.
 
G

Guest

Hi Graham,
Code for delete button is:
Private Sub CmdRemoveDrug_Click()
Dim RemoveID As Long
RemoveID =
[Forms]![Frm_EditBooking]![Sub_SelectedDrug]![lng_SelectedEquipmentID]
Call CBF_RemoveEquipment(RemoveID)
Me!Sub_SelectedDrug.Form.Requery
End Sub

AND the called function is:
Function CBF_RemoveEquipment(RemoveID As Long)
On Error GoTo CBF_RemoveEquipment_ERR
Dim strsql As String
If IsNull(RemoveID) Then
Exit Function
End If
DoCmd.SetWarnings False
strsql = "Delete * FROM Tbl_Wrk_SelectedEquip " _
& "WHERE lng_SelectedEquipmentID = " & RemoveID

DoCmd.RunSQL strsql
DoCmd.SetWarnings True
Exit Function

I'll check out your SelHeight suggestion in the meantime. Thanks again! Greg

Graham Mandeno said:
Hi Greg

Can you please post the code for your delete button?

You can tell if a form has a record selected by checking its SelHeight
property.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Greg said:
Hi Graham, Thanks for your suggestions. Unfortunately it looks like that
property isn't supported. What I am trying to do is find some way to check
if
a record has been selected in a subform. My plan was to use conditional
formating to highlight the selected record then check if the backcolor had
changed. If the backcolor had changed, the record would be deleted when I
clicked my deleterecord button. The problem I am having is, that even
though
I have not selected a record in the subform, the first record in the
subform
gets deleted when I click my deleterecord button. Can you think of any way
around this? Thanks Again, Greg
 
G

Graham Mandeno

Hi Greg

This code will get the lng_SelectedEquipmentID value from the record that
currently has the focus in your subform. Do you want it to work only if the
record selector on the left has been clicked? If so, then the SelHeight
test should do the trick. You should probably also check that multiple
records have not been selected.

With Me!Sub_SelectedDrug.Form
Select Case .SelHeight
Case 1
Call CBF_RemoveEquipment(!lng_SelectedEquipmentID)
.Requery
Case 0
MsgBox "You have not selected a record"
Case Else
MsgBox "Please select only one record"
End Select
End With

You could also delete the record directly in the subform, so in the Case 1
part:
.Recordset.Delete

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



Greg said:
Hi Graham,
Code for delete button is:
Private Sub CmdRemoveDrug_Click()
Dim RemoveID As Long
RemoveID =
[Forms]![Frm_EditBooking]![Sub_SelectedDrug]![lng_SelectedEquipmentID]
Call CBF_RemoveEquipment(RemoveID)
Me!Sub_SelectedDrug.Form.Requery
End Sub

AND the called function is:
Function CBF_RemoveEquipment(RemoveID As Long)
On Error GoTo CBF_RemoveEquipment_ERR
Dim strsql As String
If IsNull(RemoveID) Then
Exit Function
End If
DoCmd.SetWarnings False
strsql = "Delete * FROM Tbl_Wrk_SelectedEquip " _
& "WHERE lng_SelectedEquipmentID = " & RemoveID

DoCmd.RunSQL strsql
DoCmd.SetWarnings True
Exit Function

I'll check out your SelHeight suggestion in the meantime. Thanks again!
Greg

Graham Mandeno said:
Hi Greg

Can you please post the code for your delete button?

You can tell if a form has a record selected by checking its SelHeight
property.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Greg said:
Hi Graham, Thanks for your suggestions. Unfortunately it looks like
that
property isn't supported. What I am trying to do is find some way to
check
if
a record has been selected in a subform. My plan was to use conditional
formating to highlight the selected record then check if the backcolor
had
changed. If the backcolor had changed, the record would be deleted when
I
clicked my deleterecord button. The problem I am having is, that even
though
I have not selected a record in the subform, the first record in the
subform
gets deleted when I click my deleterecord button. Can you think of any
way
around this? Thanks Again, Greg
 

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