Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Strings and Variables (Type Mismatch)

Status
Not open for further replies.

tbiceps

IS-IT--Management
Nov 23, 2005
106
US
I tend to have problems with syntax when mixing strings with variables. For instance,

Code:
MsgBox "This is:" + variable

gives me a type mismatch error

or in a SQL statement. Can someone direct me to some Faq or other resource.
 
MsgBox "This is:" [!]&[/!] variable

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The pluss sign is often used for mathematical purposes. Using + when dealing with text and numbers, might possibly lead Access to believe math is intended -> type mismatch. Try using ampersand (&) for concatenations.

Roy-Vidar
 
Here is another example:

Code:
INTO TBL_Index ([Report ID],[Field ID]) VALUES " + "('" + RptValue + "') " + "('" + UniqueFieldID + "') "
 
Code:
INTO TBL_Index ([Report ID],[Field ID]) VALUES ('" [!]&[/!] RptValue [!]&[/!] "'[!],[/!]'" [!]&[/!] UniqueFieldID [!]&[/!] "') "

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
However, do not write off the + sign for concatenating values especially variants. You can take advantage of null propagation where a null value + value = null
Here is an example that I always use in a database where I store: LastName, FirstName, and MI, but I want the form or report to look like this
FirstName MI. LastName
or
FirstName LastName (when there is no MI)


? "FirstName" & " MI" + "." & " LastName"
FirstName MI. LastName

? "FirstName" & null & "." & " LastName"
FirstName. LastName

But
? "FirstName" & null + "." & " LastName"
FirstName LastName

In the above I hard coded Firstname,MI, Lastname but these would be references to control values or fields.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top