How to get a control name

L

lcox400w

I continue to strugle with how to obtain a control name and then take some
action on it when its not the current control. Can anyone point me in the
direction of how to obtain the control name of a field? If the below code
makes sense, I want to test 2 fields and if they have a value or something in
them then leave them active, if they dont, disable them, but i'm stuck on how
to get the control name into the code below.

thanks

Dim actl As String
actl = Me.Controls

Select Case actl

Case "OISNO"
If IsEmpty(OISNO) Then Me.OISNO.Enabled = False

Case "ICDNO"
If IsEmpty(ICDNO) Then Me.ICDNO.Enabled = False

End Select
 
M

Marshall Barton

lcox400w said:
I continue to strugle with how to obtain a control name and then take some
action on it when its not the current control. Can anyone point me in the
direction of how to obtain the control name of a field? If the below code
makes sense, I want to test 2 fields and if they have a value or something in
them then leave them active, if they dont, disable them, but i'm stuck on how
to get the control name into the code below.

Dim actl As String
actl = Me.Controls

Select Case actl

Case "OISNO"
If IsEmpty(OISNO) Then Me.OISNO.Enabled = False

Case "ICDNO"
If IsEmpty(ICDNO) Then Me.ICDNO.Enabled = False

End Select


Seems like you already know the control names??

How about just using:

Me.OISNO.Enabled = Not IsNull(Me.OISNO)
 
P

Piet Linden

I continue to strugle with how to obtain a control name and then take some
action on it when its not the current control.  Can anyone point me in the
direction of how to obtain the control name of a field?  If the below code
makes sense, I want to test 2 fields and if they have a value or something in
them then leave them active, if they dont, disable them, but i'm stuck onhow
to get the control name into the code below.

thanks

Dim actl As String
actl = Me.Controls

Select Case actl

    Case "OISNO"
        If IsEmpty(OISNO) Then Me.OISNO.Enabled = False

    Case "ICDNO"
        If IsEmpty(ICDNO) Then Me.ICDNO.Enabled = False

End Select

Where do you want to do this? In the Current event of the form?
Me.Controls("MyControl").Enabled=Not IsEmpty(Me.Controls("MyControl"))

you don't really need to declare a control object unless you're going
to process a whole lot of controls with the same block of code.
 
L

lcox400w

I was thinking of doing it when the form loads. I want to test to see if
there is anything in those 2 fields. If not, I want to disable them. If
there is I want to leave the one that has the value enabled so the user can
edit the field if they need to change the value.
 
L

lcox400w

To clarify my original quesiton, its a problem I keep running into.

On some of my forms, I want to have some code run against various fields,
some are text boxes, some are combo boxes, the code is generally to enable or
disable a field. Or maybe I want to test to see if several fields are null
or not.

I thought the best way to do this would be to do a select case, where I can
specify the name of the field and when that code was called upon, it could go
through the code and if it hits "Case DateOcc", it would run that code under
that case statement, if I then had "Case Location", it woudl then run the
code under that statement, but I dont know how to go about setting up the
select portion. I have tried varous methods such as

me.name (returns the form name)
me.ControlSource (I found out thats the source of the data, not the name of
the field)
I was then trying Me.Controls as my next option to see if that would work.
After several hours, I decided to post the quesiton for help.

I found code Screen.ActiveControl.CurrentControl (I think thats it, doing it
from memory) but since I'm not in a current control, that doesnt work either.

I keep running into this same issue on forms I want to go through a
select/case statement to make changes to speciic fields, I just cant figure
out how to get the select portion to work properly so when it hits the CASE
poriton of the code, the CASE contains the control name. I hope this makes
sense?

As for your note about IsEmpty, sounds like I should be using isnull, I
wasnt sure how isempty would work, but I was going to try it.

I have not locked a control before, I will explore that and how it looks to
the end sure. thanks for the tip.

I hope this make sense and you can give me the key to unlock my problem.

thanks
 
L

lcox400w

I like the idea of using a back color. I actually wanted to setup a
case/select statement when the form loads to identify which fields are null
that need to be filled in and use a back color to identify those, but I ran
into 2 issues. The curernt thread, of how to write the select portion so
when it hits the CASE line the field name is in there and will run the code
against that field.

Second issue I could not find an example of how to change the back color of
a field.

any help would be appreciated.

thanks so much to everyone.
 

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