S
ScottH---
I have a form that displays pairs of values. The value pairs are data that
are supposed to match between a mainframe and our SAP system.
I am trying to run through the form, checking each control to see if its
value matches what is in the opposite control. If they do not match, I want
to highlight the control. If they do match, I want to make the text gray.
My problem is that the loop won't accept my use of variables to reference a
control. I get errors, which I have marked below.
Can someone look at this and tell me what I'm doing wrong?
--------------------------------------------------------------------------
Private Sub Form_Load()
Dim ctlControl As Control
Dim ctlOppositeControl As Control
Dim strControlName As String
Dim strOppositeControlName As String
Dim strFirst As String
Dim strControlValue As Variant
Dim strOppositeControlValue As Variant
For Each ctlControl In Me.Controls
If TypeName(ctlControl) = "TextBox" Then
strControlName = ctlControl.Properties("Name").Value
strFirst = Left(strControlName, 1)
'Get the name of the strOppositeFieldName
If strFirst = "S" Then
strOppositeControlName = "GEMS" & Mid(strControlName, 3)
'THIS IS THE FIRST SPOT WHERE I GET THE ERROR...
'it seems to be looking for
'a control literally named "strOppositeControlName". It
returns an
'error when it can't find any control with that name.
Set ctlOppositeControl = Me!strOppositeControlName
Else
strOppositeControlName = "SAP" & Mid(strControlName, 4)
Set ctlOppositeControl = Me!strOppositeControlName
End If 'end of getting value for strOppositeFieldName
'Get the current values in the two fields
strControlValue = ctlControl.Value
'strOppositeControlValue = ctlOppositeControl.Value
'Evaluate if the fields match
If Me!ctlControl.Value = "Me!ctlOppositeControl.Value" Then
'Values match, so make the text gray and normal
Me!strFieldName!ForeColor = 6710886
Me!strFieldName!FontWeight = "Bold"
Else 'Values don't match, so highlight the control
Me!strFieldName!ForeColor = "Red"
Me!strFieldName!FontWeight = "Bold"
End If
End If
Next ctlControl
End Sub
Thanks!
Scott
are supposed to match between a mainframe and our SAP system.
I am trying to run through the form, checking each control to see if its
value matches what is in the opposite control. If they do not match, I want
to highlight the control. If they do match, I want to make the text gray.
My problem is that the loop won't accept my use of variables to reference a
control. I get errors, which I have marked below.
Can someone look at this and tell me what I'm doing wrong?
--------------------------------------------------------------------------
Private Sub Form_Load()
Dim ctlControl As Control
Dim ctlOppositeControl As Control
Dim strControlName As String
Dim strOppositeControlName As String
Dim strFirst As String
Dim strControlValue As Variant
Dim strOppositeControlValue As Variant
For Each ctlControl In Me.Controls
If TypeName(ctlControl) = "TextBox" Then
strControlName = ctlControl.Properties("Name").Value
strFirst = Left(strControlName, 1)
'Get the name of the strOppositeFieldName
If strFirst = "S" Then
strOppositeControlName = "GEMS" & Mid(strControlName, 3)
'THIS IS THE FIRST SPOT WHERE I GET THE ERROR...
'it seems to be looking for
'a control literally named "strOppositeControlName". It
returns an
'error when it can't find any control with that name.
Set ctlOppositeControl = Me!strOppositeControlName
Else
strOppositeControlName = "SAP" & Mid(strControlName, 4)
Set ctlOppositeControl = Me!strOppositeControlName
End If 'end of getting value for strOppositeFieldName
'Get the current values in the two fields
strControlValue = ctlControl.Value
'strOppositeControlValue = ctlOppositeControl.Value
'Evaluate if the fields match
If Me!ctlControl.Value = "Me!ctlOppositeControl.Value" Then
'Values match, so make the text gray and normal
Me!strFieldName!ForeColor = 6710886
Me!strFieldName!FontWeight = "Bold"
Else 'Values don't match, so highlight the control
Me!strFieldName!ForeColor = "Red"
Me!strFieldName!FontWeight = "Bold"
End If
End If
Next ctlControl
End Sub
Thanks!
Scott