Highlighting subform nulls

G

george 16-17

Greetings all,

I am fairly new to Access and currently using Access 2003. I need some
assistance coding a subform(subfrmEmpHistory) that updates the main form
(frmEmpDemo). The problem I am having is how the handle the required subform
text boxes if left incomplete, I would like the textbox backcolor to
hightlight it in red. I was able to do this with conditional formatting, but
is there code for this?

This is my current code:
Private Sub Form_AfterUpdate()

On Error GoTo Err_Handler

Dim ctl As Control

If Not IsNull(ctlControlType) Then
If Me.Dirty Then
Me.Dirty = False
End If
With Forms!frmEmpDemo
!txtJobTitleEmpDemo = Me.txtNewJobTitle.Value
!txtDepartmentEmpDemo = Me.txtNewDepartment.Value
!cboWorkStatusEmpDemo = Me.txtNewWorkStatus.Value
End With
End If

If IsNull(ctlControlType) Then
.BackColor = 255 'This code is not working.
End With
End If

Forms!frmEmpDemo.Requery
Forms!frmEmpDemo.Refresh

Exit Sub

Err_Handler:
MsgBox "Please enter requested information. " & Error, vbOKOnly, "Required
field!"

End Sub


Thanks in advance,
george
 
D

Dennis

Well, you need to put the code block INSIDE a "WITH" construct. Additionally,
one cannot have "conditional" END WITH statements; that is, place them inside
an IF construct, and expect them to work properly.

For your specific need, you might use something like:

if isnull(me.MyControl) then
me.MyControl.BackColor = (whatever)
else
me.MyControl.BackColor = (whatever)
end if
 
G

george 16-17

Hi Dennis,

Thanks for taking a look. I appreciate the reply. I found the END WITH
problem, which was a leftover from previous coding attempts.

I will try your code and post back with any continued problems.

Again, much appreciated,
george
 

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