Trouble with this code

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

Good morning!!
I'm having some dificulty with the following code:
Dim ctl As Control
Dim chkName As TextBox
Dim name As String


For Each ctl In Me.Controls

If ctl.Tag = "chk" Then
name = ctl.name
chkName = name ' doesn't work

If IsNull(chkName.Value) Then
chkName.Value = "N/a"
Else
' leave-it like this.
End If

Else
' do nothing, stays invisible.
End If


Next ctl

Here's what this code is supposed to do for me:
I've mark 6-7 textbox with a TAG="chk". When the system
cycles thru all the controls, it only stop on those ones
marked "chk".
Once it has found one, it needs to check if that
perticular textbox is empty, if it is, it will affect
the "N/a" string to that same textbox. The code below is
trying to do that but as you can see, its missing a few
things....

Can someone help me please!!!
Thanks in advance for any help you can provide me with!
PAtrick
 
Patrick,

The following might work better for you ...

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag = "chk" Then
If IsNull(ctl) Then
ctl = "N/A"
End If
End If
Next ctl

In this case, as you are looping through the controls on your form, you do
not need to re-assign "ctl" to anything else once the code has identified it
as having "chk" in its Tag property.

Also, for future reference, Access has a Reserved Words list, in which it
identifies words that the user should not use for variables, field names,
etc. These words are already used by Access and will cause much difficulty
and unexpected results if you try to re-use them; for example, the word
"name". Forms, Controls and other objects have a Name Property, so it is
good to get a feel for what these Reserved Words are. Here is a link:

http://support.microsoft.com/default.aspx?scid=kb;en-us;209187


hth,
 
Back
Top