473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Adding a Character to a string, using INSERT INTO....

kcdoell
230 100+
Hello:

I have a Insert Into command that currently works:

DoCmd.RunSQL "INSERT INTO TypeEorD ( EorDName, EorD ) SELECT Trim([CatType] & '_' & Trim(Category)), Trim(CatType);"

"Category" is a manual input text box
"CatType" is a combo box where the user selects either "Deduction" or "Earning"

If the user inputted in the Category text box "Cola" and Selected Earning from the CatType, the current code would insert into my table (TypeEorD) the following result:

EorDName =Earning_Cola
EorD=Earning

What I am trying to do is get the following result:

EorDName =E_Cola
EorD=Earning

I thought changing the code to the following would produce the result but it does not:

DoCmd.RunSQL "INSERT INTO TypeEorD ( EorDName, EorD ) SELECT Trim(Left([CatType],1) & '_' & Trim(Category)), Trim(CatType);"

The result I get is this:
EorDName =_Cola
EorD=Earning

Does anybody have any insight?

Thanks
Jan 4 '08 #1
3 3562
ADezii
8,834 Expert 8TB
Hello:

I have a Insert Into command that currently works:

DoCmd.RunSQL "INSERT INTO TypeEorD ( EorDName, EorD ) SELECT Trim([CatType] & '_' & Trim(Category)), Trim(CatType);"

"Category" is a manual input text box
"CatType" is a combo box where the user selects either "Deduction" or "Earning"

If the user inputted in the Category text box "Cola" and Selected Earning from the CatType, the current code would insert into my table (TypeEorD) the following result:

EorDName =Earning_Cola
EorD=Earning

What I am trying to do is get the following result:

EorDName =E_Cola
EorD=Earning

I thought changing the code to the following would produce the result but it does not:

DoCmd.RunSQL "INSERT INTO TypeEorD ( EorDName, EorD ) SELECT Trim(Left([CatType],1) & '_' & Trim(Category)), Trim(CatType);"

The result I get is this:
EorDName =_Cola
EorD=Earning

Does anybody have any insight?

Thanks
This code has been tested and will achieve the desired result:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. If IsNull(Me![Category]) Or IsNull(Me![CatType]) Then Exit Sub
  4.  
  5. DoCmd.SetWarnings False
  6.   strSQL = "INSERT INTO TypeEorD(EorDName, EorD) "
  7.   strSQL = strSQL & "Values('" & Left$(Trim(Me![CatType]), 1) & "_" & Trim(Me![Category])
  8.   strSQL = strSQL & "','" & Trim(Me![CatType]) & "')"
  9.     DoCmd.RunSQL strSQL
  10. DoCmd.SetWarnings True
Jan 4 '08 #2
kcdoell
230 100+
Your solution worked flawlessly. Thanks a million.

Keith.
Jan 4 '08 #3
ADezii
8,834 Expert 8TB
Your solution worked flawlessly. Thanks a million.

Keith.
You are quite welcome.
Jan 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Garry | last post by:
Hi, I am new to python, hope someone can help me here: I have a MS Access exported .txt file which is tab delimited in total 20 columns, now I need to add another column of zero at the 4th column...
10
by: M Bourgon | last post by:
I'm trying to figure out how to find the last whitespace character in a varchar string. To complicate things, it's not just spaces that I'm looking for, but certain ascii characters (otherwise,...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
20
by: Bryan | last post by:
hello all... im trying to add a record to an sql db on ms sql server 2000, using vb.net. seems to be working.. except for one thing, one of the columns in the database is a bit datatype, and...
6
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so...
7
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to...
5
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
1
by: Kageoni2 | last post by:
I'm trying to add new records to my database using 4 textboxes, one for each field in my databases table. I've got ID, Firstname, Surname and Course. But I can't figure out at all how to link...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.