473,386 Members | 1,832 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,386 software developers and data experts.

Concatenate in a VBA "INSERT INTO" script

I am trying to update an older MS Access 2010 VBA script that is embedded into a button click. This button will update another Access table for another squadron. I need to change a couple things around however because my update will basically break this script by not sending all the required information.

What needs to be done is there is a "Top3Comments" and a "Call Sign" entry that have their own boxes. What I have updated is now requiring the "Top3Comments" to be concatenated with the mission commander "Commander" and the "Call Sign" to be concatenated with "C/S_Number". I need the combined output of both of those to output to a single cell in the table.

I am assuming that I will just use a JOIN function after calling all variables into a Dim? I am not really sure how to accomplish this though. Anyone have any ideas.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Btn_Update_Top_3_Buddy_Click()
  2. 'When you click the Update button, this procedure will delete the selected day's comments in the [TOP 3 LOG Table]
  3. 'And then add the current mission comments to the [TOP 3 LOG Table].
  4. On Error GoTo Err_Btn_Report_Click
  5.  
  6.     Dim DeleteQuery As String
  7.     Dim InsertQuery As String
  8.  
  9.  
  10.     DoCmd.SetWarnings False
  11.     DeleteQuery = "DELETE [TOP 3 LOG Table].Squadron, [TOP 3 LOG Table].Date FROM [TOP 3 LOG Table] " _
  12.                   & "WHERE (((([TOP 3 LOG Table].Squadron='489 RS')OR([TOP 3 LOG Table].Squadron='427 RS')OR([TOP 3 LOG Table].Squadron='306 IS')))" _
  13.                   & "AND (([TOP 3 LOG Table].Date)=#" & Forms![Ops Sup]![Date_SITREP] & "#));"
  14.  
  15.  
  16.     DoCmd.RunSQL DeleteQuery
  17.  
  18.     InsertQuery = "INSERT INTO [TOP 3 LOG Table] ( [Date], Squadron, Top3Name, Top3Comments, " _
  19.                 & "[Line#], Aircraft, Block, SortieType, [NE/CNX], Reason, FlightTime, [Call Sign], [Tail#]) " _
  20.                 & "SELECT Missions.Date_Mission, Missions.Squadron, Missions.Top3Name, Missions.Top3Comments, " _
  21.                 & "Missions.[Line#], Missions.Aircraft, Missions.Block, Missions.[Sortie Type], Missions.[NE/CNX], " _
  22.                 & "Missions.Reason, Missions.FlightTime, Missions.[Call Sign], Missions.[Tail#] " _
  23.                 & "FROM Missions " _
  24.                 & "WHERE (((Missions.Date_Mission)= #" & Forms![Ops Sup]![Date_SITREP] & "#));"
  25.  
  26.     DoCmd.RunSQL InsertQuery
  27.     DoCmd.SetWarnings True
  28.  
  29.     MsgBox ("Top 3 Buddy updated.")
  30.  
  31. Exit_Btn_Report_Click:
  32.     Exit Sub
  33.  
  34. Err_Btn_Report_Click:
  35.     DoCmd.SetWarnings True
  36.     MsgBox Err.Description
  37.  
  38. End Sub
This is the current code that I have.
Sep 11 '13 #1

✓ answered by zmbd

What needs to be done is there is a "Top3Comments" and a "Call Sign" entry that have their own boxes. What I have updated is now requiring the "Top3Comments" to be concatenated with the mission commander "Commander" and the "Call Sign" to be concatenated with "C/S_Number". I need the combined output of both of those to output to a single cell in the table.
Respectfully, why are you denormalizing your database?
What happens with the callsign changes... I have known this to happen in the Navy.

Should be no need for VBA nor to denormalize your database:
- Start out with a simple select query in the query designer.
- Make sure that this pull all of the original data that you desire.
- Now add a calculated field that will create your new value:nameoffield: [firstfield] & [secondfield] this would adjoin the two fields without space between.
- Once this is done and the results are what you need.
- At this point you haven't altered your database; however, you now have the new values you are after.

-!- IF you insist on denormalizing your database at this point, then you can base an insert query from the designer on this new query.

Also it is not best practice to use a backslash in the field names... as you are doing an update, this might be the time to put the effort into changeing everything that refers to such.
-alphanumeric:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access

1 2915
zmbd
5,501 Expert Mod 4TB
What needs to be done is there is a "Top3Comments" and a "Call Sign" entry that have their own boxes. What I have updated is now requiring the "Top3Comments" to be concatenated with the mission commander "Commander" and the "Call Sign" to be concatenated with "C/S_Number". I need the combined output of both of those to output to a single cell in the table.
Respectfully, why are you denormalizing your database?
What happens with the callsign changes... I have known this to happen in the Navy.

Should be no need for VBA nor to denormalize your database:
- Start out with a simple select query in the query designer.
- Make sure that this pull all of the original data that you desire.
- Now add a calculated field that will create your new value:nameoffield: [firstfield] & [secondfield] this would adjoin the two fields without space between.
- Once this is done and the results are what you need.
- At this point you haven't altered your database; however, you now have the new values you are after.

-!- IF you insist on denormalizing your database at this point, then you can base an insert query from the designer on this new query.

Also it is not best practice to use a backslash in the field names... as you are doing an update, this might be the time to put the effort into changeing everything that refers to such.
-alphanumeric:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access
Sep 11 '13 #2

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

Similar topics

2
by: SWN | last post by:
hi. Trying to concatenate two columns: select uname+' '+uaddress as NameAdr from tblUser I only get the first field, name!!?? The datatype is both nvarchar. 100 and 50 chars long. If I...
3
by: Voetleuce en f?nsievry | last post by:
G'day I'm looking for a script that can search multiple instances of Google (or other search engines optionally). The user types in a single word in the text field, presses ENTER or the submit...
3
by: Dave | last post by:
I need to concatenate serveral text files into a larger file. I borrowed some code and patched together a batch file that runs in the command processor and looks like this: echo off chdir...
7
by: farsad nasseri | last post by:
Hi I have written a small transformation routine that converts my XML file into a bunch of Insert statements in another file. The file will be in the following format but much longer: INSERT...
4
by: Wladimir Borsov | last post by:
Ok, think of let say 10 different web pages on the internet. Each of them are usual html web pages. Nothing special. What I want to do now is to create a new meta resp. grouping web page which...
1
by: Accessgoddess | last post by:
Hi I've downloaded the PDFClass library from ACG PDF and used their script to export a report to a pdf file. That was great. However what I really need to do for more than one client is take...
6
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by...
6
by: Raju | last post by:
String a=Test String b=test@test.com How cn I concatenate this to get String c ="""Test"" <test@test.com>"
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
4
by: calibunny | last post by:
We are trying to move files to SharePoint but need to rename them first since many have invalid characters. A previous developer started the script below. Any suggestions on how to adept it to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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.