Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Caption in message

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MrH - 03 May 2007 16:19 GMT
I was looking at some code for validation.... like this....

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next

Now the problem is this displays the field name.... which to alot of users
might be confusing. For example...... The "First Name" field or "Last Name"
field on a form might display.... "txtFName" or txtLName" ........ If the
user sees this in a message box they might not really know what field is
required!
What I want to do is display the Caption.. somethin like "ctl.Caption" not
"ctl.name" but can't seem to find any syntax that works.
Anyone help?

Thanks
Douglas J. Steele - 03 May 2007 16:35 GMT
Each control has a Tag property that you can use however you want. Stick
whatever description you want in the Tag property, and then use

msg = "Data Required for '" & ctl.Tag & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I was looking at some code for validation.... like this....
>
[quoted text clipped - 25 lines]
>
> Thanks
MrH - 03 May 2007 17:50 GMT
>Each control has a Tag property that you can use however you want. Stick
>whatever description you want in the Tag property, and then use
>
> msg = "Data Required for '" & ctl.Tag & "' field!" & nl & _
> "You can't save this record until this data is provided!" & nl & _

That won't work......... The "Tag" is being used to identify which fields to
check.....
"If ctl.Tag = "*" And Trim(ctl & "") = "" Then"
So....... It would work if you changed the tag on every field and had
multiple IF...Then statements.
But..... Not what I want to do.......
Thats what has been frustrating trying to get an answer on this one! OR
simply why it wont work. The "caption" can be set in the table. THAT is what
I am really trying to reference.
Douglas J. Steele - 03 May 2007 18:52 GMT
>>Each control has a Tag property that you can use however you want. Stick
>>whatever description you want in the Tag property, and then use
[quoted text clipped - 13 lines]
> what
> I am really trying to reference.

While it's a pain, you can store multiple pieces of information in the Tag
property.

Put, say, a semicolon after the asterisk, followed by the caption you wish
to use:

*;Caption

You'd then use:

If Left(ctl.Tag, 1) = "*" And Trim(ctl & "") = "" Then

and

msg = "Data Required for '" & Mid(ctl.Tag, 3) & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _

Heck, you don't even really need the semicolon in this case: just put an
asterisk in front of the caption (and use Mid(ctl.Tag, 2) in the assignment
statement instead)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

marius - 03 May 2007 19:25 GMT
> ... The "caption" can be set in the table. THAT is what
>  I am really trying to reference.

You can try something like:
msg= ......  & Me.Recordset.Fields(ctr.ControlSource).Properties("Caption")
&  ....

(if property isn't set you get an error, trap it)

Signature

HTH,
Màrius - BCN

GH - 03 May 2007 16:41 GMT
Textbox controls do not have a Caption property.  You can try using
the StatusBarText or ControlTipText properties to provide more user-
friendly descriptions of the textbox fields.

- GH

> I was looking at some code for validation.... like this....
>
[quoted text clipped - 27 lines]
> --
> Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200705/1
Marshall Barton - 03 May 2007 17:10 GMT
>I was looking at some code for validation.... like this....
>
[quoted text clipped - 21 lines]
>What I want to do is display the Caption.. somethin like "ctl.Caption" not
>"ctl.name" but can't seem to find any syntax that works.

Captions are in  labels, not text boxes.  **IF** the text
box has an attached label, then you can retrive the label's
caption using:

    ctl.Controls(0).Caption

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.