Concatenate text with field (1 Viewer)

rkrause

Registered User.
Local time
Yesterday, 18:58
Joined
Sep 7, 2007
Messages
343
I am trying to add text to a field in my report, here is my example on what im trying to do.
="This benefit statement is prepared for:" & [Fullname]

when i have that in a textbox i am just getting #Error
 

boblarson

Smeghead
Local time
Yesterday, 18:58
Joined
Jan 12, 2001
Messages
32,059
You probably have a control on your report named FullName and if you rename it to txtFullName and then use the [FullName] as you are, it should work fine.

If you have name auto correct turned on (which if you do, I would suggest turning it off as it is also known as name auto CORRUPT), it will rename your [FullName] to [txtFullName] and you'll need to change it back to [FullName] for it to work.
 

bulrush

Registered User.
Local time
Yesterday, 21:58
Joined
Sep 1, 2009
Messages
209
Always, always, always, rename ALL controls with a special prefix. It will save you a lot of headaches. Here are the prefixes I use:
labels = "lbl"
text box = "txt"
subreports/subforms = "subr" or "subf"
list box = "lst"
combo box = "cbx"
command button = "cmd"

Some people use different prefixes. But use something.
 

Megan

Registered User.
Local time
Yesterday, 21:58
Joined
Jun 3, 2011
Messages
23
Thank you for the link to the commonly used naming conventions, vbaInet. I'm glad this thread came up in my search for just that.

Now for the process of renaming and updating macros and code in this database. Hopefully it won't be too spaghetti-like a process; if anyone knows of a good method and/or good tools for the renaming process (finding controls, macros, and code that reference the renamed controls, objects, etc.), my noob ears are perked. :)

I did find the "In this Database" list of objects with macros so that might prove to be somewhat useful. I'll also try to search out more info in access and online, as I'm sure it has been discussed many times before.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:58
Joined
Jan 20, 2009
Messages
12,853
Always, always, always, rename ALL controls with a special prefix.

Not everyone uses control type based naming conventions (known as Hungarian notation) Personally I think they are highly overrated because I don't believe the control type is the most important factor in a name.

A similar convention is used by many developers to indicate the variable datatype and some even go so far as to designate the datatype of a field in the same way or put fld in front of every fieldname.

It is important to be organised in the naming of things but the obsession with type is not the be all and end all of naming.

There are plenty of other (at least) equally valid naming patterns that have nothing to do with the controltype.

For example a form might have textboxes, combos, buttons all related to manipulate dates. I start them all with Date and that keeps like together with like.

Why anyone thinks a naming system that isolates a label from the control it is associated with is beyond me. And how often does it really matter if the control is a listbox or a combo?

Renaming objects in a large project is a nightmare rarely worth contemplating but the free V-Tools Total Deep Search is quite good. Be very careful though or you can find things changing they you did not expect.
 
Last edited:

boblarson

Smeghead
Local time
Yesterday, 18:58
Joined
Jan 12, 2001
Messages
32,059
And how often does it really matter if the control is a listbox or a combo?
It can, because they don't have exactly the same properties and sometimes it is necessary to know which is which. Combo's don't have a multi-select property. They don't have a ItemsSelected collection. And that can go with other controls as well.

I prefer to work with the control type prefixes as I like how it works for me. But it isn't for everyone, but if your boss says your are to follow certain standards then you get to use those standards regardless of personal preference. :D
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:58
Joined
Jan 20, 2009
Messages
12,853
It can, because they don't have exactly the same properties and sometimes it is necessary to know which is which.

Certainly, but what I question is whether the developer needs to be reminded of the control type absolutely every time they make reference to it from anywhere in the whole project.

Indeed, when using this naming convention they do need to know the contoltype better than anything else to make a reference to it and have Intellisense prompt with it. In my example above I know that I want to refer to one of the date related controls and find them grouped together in Intellisense instead of strewn throughout the list.

I find it even more bizarre when Hungarian Notation is used in variable names. Confronted with names like DateStart and FirstName how many developers think,

"Oh dear I wonder what datatype they would be? Better make them dteDateStart and strFirstName so I will remember." :rolleyes:

Moreover if there is the slighest question, the definiton of the variable available in the context menu on every mention of the variable.

This convention was born in vbs where datatypes are not explicitly defined. They are an anachronism in VBA.

I do use them in some places where they are almost universal such as strSQL. I also use them on variables and controls when posting code fragments on this site because it does convey useful information in this context.

I prefer to work with the control type prefixes as I like how it works for me.

Humans are creatures of habit and will continue to use what they are comfortable with and that is fine. This notation is used throughout the MS Help so it is not surprising that it is picked up by many devolpers (and their clipboard).

However it is one reason why I always carefully analyse practices from first principles when learning any new subject. Conventional wisdom is often found wanting and often the stronger the case made by the promoter, the weaker the basis of the practice. I found several widely promulgated phurphies while learning Access.

In this thread I was really trying to balance the post by bulrush which suggested Hungarian Notation was essential, particulary after Megan posted her intention to take on the onerous task of renaming all the objects in her database. :eek:

But it isn't for everyone, but if your boss says your are to follow certain standards then you get to use those standards regardless of personal preference. :D

You hit the nail on the head there Bob.
 

Megan

Registered User.
Local time
Yesterday, 21:58
Joined
Jun 3, 2011
Messages
23
Thank you both for the perspectives. It seems that a "best of both worlds" approach would be to put the data type or something similar at the beginning and the control type at the end. For example:

DateDeliveryCbo
DateOrderTxt
CalcLeadTimeTxt

From what I'm gleaning from this discussion, this method could prove to be quite functional. They might get a bit long, though.

Edit: Oh, and thank you for the V-Tools link, GalaxiomAtHome! I love it and will be cautious with it as well.
 
Last edited:

Megan

Registered User.
Local time
Yesterday, 21:58
Joined
Jun 3, 2011
Messages
23
Sweet, more tools to explore! I really appreciate all the tips. I want to begin with good habits as much as is practical.
 

Users who are viewing this thread

Top Bottom