Access 2002 - Modifying Properties of Subform fields (1 Viewer)

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
Hi, new to the forum so forgive the use of incorrect terms.

I have a Form with embedded Subform, everything works well as far as moving through records. Scrolling through records on main table via Form brings up correct records of child table on Subform, so the link between the 2 tables is done properly.

I use this logic to lock/unlock a field in the subform.

Code:
Private Sub Form_Current()
  If IsNull(Me.Parent!Spec2) Then
    Me!Value2.BorderStyle = Transparent
    Me!Value2.SpecialEffect = Flat
    Me!Value2.BackStyle = Transparent
    Me!Value2.Enabled = No
    Me!Value2.Locked = Yes
  Else
    Me!Value2.BorderStyle = Solid
    Me!Value2.SpecialEffect = Sunken
    Me!Value2.BackStyle = Normal
    Me!Value2.Enabled = Yes
    Me!Value2.Locked = No
  End If
  Form.Repaint
End Sub

I confirmed with debug that the logic does set the properties properly. They are updated once and that's that. Any further passes through the logic do not update on the form. They do pass through correctly, changes are just ignored.

It doesn't matter if I use the logic from the Form and refer down, or in the Subform and refer up, the Subform never gets updated. I tried Repaint, Refresh, Requery, nothing works. I cannot count the permutations I've tried.

Robert
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 00:22
Joined
Jan 20, 2009
Messages
12,854
Property values such as Transparent and Flat are just what is displayed in the Properties window.

The actual values are numbers. They can bee seen in the enumeration of the properties. Another way is to simply read the property values from a control (as they are called) with the property you want.
 

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
Property values such as Transparent and Flat are just what is displayed in the Properties window.

The actual values are numbers. They can bee seen in the enumeration of the properties. ...

I have no clue how to do that.


... Another way is to simply read the property values from a control (as they are called) with the property you want.

I googled "read the property values from a control" and found nothing useful. I did F2 while in Code window and found these:

Code:
Property BorderStyle as Byte
Property SpecialEffect as Byte
Property BackStyle as Byte
Property Enabled as Boolean
Property Locked as Boolean
 
acCmdTransparentBackground = 288
acCmdTransparentBorder = 289

The Boolean properties were easy to deal with, it's the bytes that I don't know how to handle.

I'm also missing values for Flat/Sunken SpecialEffect, Solid BorderStyle and Normal BackStyle.

I'd need one example to start off. Help in Access Code is practically useless for detailed stuff. All I find on google are how to change colours, but I already knew how to use numbers in this situation.

Robert
 

spikepl

Eledittingent Beliped
Local time
Today, 16:22
Joined
Nov 3, 2010
Messages
6,142
MsgBox Me.MyControlName.MyPropertyName

or

debug.print Me.MyControlName.MyPropertyName
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 00:22
Joined
Jan 20, 2009
Messages
12,854
Most of the ordinary numeric properties start at zero and are in the same order as the list in the property box.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:22
Joined
Sep 12, 2006
Messages
15,695
maybe you are not seeing NULLS in the parent.

you cannot distinguish a null from a zls by inspection.
 

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
Code:
Private Sub Form_Current()
  If IsNull(Me!Spec2) Then
    Form_Parts_subform!Value2.Enabled = False
    Form_Parts_subform!Value2.Locked = True
    Form_Parts_subform!Value2.BorderStyle = 0           ' Transparent
    Form_Parts_subform!Value2.SpecialEffect = 0         ' Flat
    Form_Parts_subform!Value2.BackStyle = 0             ' Transparent
  Else
    If Form_Parts_subform!Value2.Enabled = False Then   ' Enable only if disabled
      Form_Parts_subform!Value2.Enabled = True
      Form_Parts_subform!Value2.Locked = False
      Form_Parts_subform!Value2.BorderStyle = 1         ' Solid
      Form_Parts_subform!Value2.SpecialEffect = 2       ' Sunken
      Form_Parts_subform!Value2.BackStyle = 1           ' Normal
    End If
  End If
End Sub

Now works, but cannot disable a control while it has focus if cursor happens to be on that control when click NEXT RECORD button.

Found several relevant threads but moving code to Form_BeforeUpdate is not helpful in this context.

Tried forcing focus to NEXT RECORD button like this:

Code:
Private Sub CMD_NEXT_Enter()
  Me!CMD_NEXT.SetFocus
End Sub

Got same error unable to disable a control bla bla bla.

Robert
 
Last edited:

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
Went all out with this:

Code:
Private Sub CMD_NEXT_Click()
  Me!CMD_NEXT.SetFocus
End Sub
 
Private Sub CMD_NEXT_Enter()
  Me!CMD_NEXT.SetFocus
End Sub
 
Private Sub CMD_NEXT_GotFocus()
  Me!CMD_NEXT.SetFocus
End Sub
 
Private Sub CMD_NEXT_KeyDown(KeyCode As Integer, Shift As Integer)
  Me!CMD_NEXT.SetFocus
End Sub
 
Private Sub CMD_NEXT_KeyPress(KeyAscii As Integer)
  Me!CMD_NEXT.SetFocus
End Sub
 
Private Sub CMD_NEXT_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Me!CMD_NEXT.SetFocus
End Sub

Futile attempt, same error.

Robert
 

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
I attach the database in case it helps.

- Open Form Parts
- Click NEXT
- Controls on Subform enabled/disabled depending on heading

Robert
 

Attachments

  • Electronics Inventory.zip
    553.8 KB · Views: 63

DemonDNF

Registered User.
Local time
Today, 10:22
Joined
Jan 31, 2014
Messages
77
Solved!

It's not perfect, but I set focus on an invisible control on the subform and it works.

Code:
Private Sub Form_Current()
  If IsNull(Me!Spec2) Then                              ' Check if heading is used
    Form_Parts_subform!Part_ID.SetFocus                 ' Set Focus on invisible control
    Form_Parts_subform!Value2.Enabled = False           ' Disable control
    Form_Parts_subform!Value2.Locked = True
    Form_Parts_subform!Value2.BorderStyle = 0               ' Transparent
    Form_Parts_subform!Value2.SpecialEffect = 0             ' Flat
    Form_Parts_subform!Value2.BackStyle = 0                 ' Transparent
  Else
    If Form_Parts_subform!Value2.Enabled = False Then   ' Enable only if disabled
      Form_Parts_subform!Part_ID.SetFocus               ' Set Focus on alternate control
      Form_Parts_subform!Value2.Enabled = True          ' Enable control
      Form_Parts_subform!Value2.Locked = False
      Form_Parts_subform!Value2.BorderStyle = 1             ' Solid
      Form_Parts_subform!Value2.SpecialEffect = 2           ' Sunken
      Form_Parts_subform!Value2.BackStyle = 1               ' Normal
    End If
  End If
End Sub

Keeping the Code on the Main Form is more efficient than on Subform. It executes only when upper table changes instead of every detail update on lower table.

Robert
 

Users who are viewing this thread

Top Bottom