473,385 Members | 1,829 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.

Insert a variable into an append query

84
In VB, I have created an append query that will write the results to a table. To each of the records being written, I want to include the user name of the person running the query. I know how to get the user name but do not know how to insert it, even if I can, into the append query. Is this possible? I have the statement I am running now. I get an invalid syntax error now when I run it
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command89_Click()
  2. On Error GoTo Err_Command89_Click
  3.  
  4.     Dim stGetUser As String
  5.     Dim stGetParms As String
  6.  
  7.     stGetUser = GetLoginName()
  8.  
  9.     stGetParms = "INSERT INTO TEST ( JOB_ID, PARAMETER_VALUE, stGetUser as User) " & _
  10.     "SELECT JOB_PARAMETERS.JOB_ID, JOB_PARAMETERS.PARAMETER_VALUE " & _
  11.     "FROM JOB_PARAMETERS " & _
  12.     "WHERE (((JOB_PARAMETERS.PARAMETER_NAME) = 'physicalId')) " & _
  13.     "GROUP BY JOB_PARAMETERS.JOB_ID, JOB_PARAMETERS.PARAMETER_VALUE"
  14.     DoCmd.RunSQL stGetParms
  15.  
  16. Exit_Command89_Click:
  17.     Exit Sub
  18.  
  19. Err_Command89_Click:
  20.     MsgBox Err.Description
  21.     Resume Exit_Command89_Click
  22.  
  23. End Sub
Apr 6 '08 #1
2 5031
ADezii
8,834 Expert 8TB
In VB, I have created an append query that will write the results to a table. To each of the records being written, I want to include the user name of the person running the query. I know how to get the user name but do not know how to insert it, even if I can, into the append query. Is this possible? I have the statement I am running now. I get an invalid syntax error now when I run it

Private Sub Command89_Click()
On Error GoTo Err_Command89_Click

Dim stGetUser As String
Dim stGetParms As String

stGetUser = GetLoginName()

stGetParms = "INSERT INTO TEST ( JOB_ID, PARAMETER_VALUE, stGetUser as User) " & _
"SELECT JOB_PARAMETERS.JOB_ID, JOB_PARAMETERS.PARAMETER_VALUE " & _
"FROM JOB_PARAMETERS " & _
"WHERE (((JOB_PARAMETERS.PARAMETER_NAME) = 'physicalId')) " & _
"GROUP BY JOB_PARAMETERS.JOB_ID, JOB_PARAMETERS.PARAMETER_VALUE"
DoCmd.RunSQL stGetParms

Exit_Command89_Click:
Exit Sub

Err_Command89_Click:
MsgBox Err.Description
Resume Exit_Command89_Click

End Sub
Let's assume you have a Field (USER_NAME) in your Table (Test) that will store the User's Name, then:
Expand|Select|Wrap|Line Numbers
  1. 'Dim stGetUser As String                  'don't need
  2. Dim stGetParms As String
  3.  
  4. 'Don't need
  5. 'stGetUser = GetLoginName()
  6.  
  7. stGetParms = "INSERT INTO TEST ( JOB_ID, PARAMETER_VALUE, USER_NAME) " & _
  8. "SELECT JOB_PARAMETERS.JOB_ID,  JOB_PARAMETERS.PARAMETER_VALUE, GetLoginName() As QUser " & _
  9. "FROM JOB_PARAMETERS " & _
  10. "WHERE (((JOB_PARAMETERS.PARAMETER_NAME) = 'physicalId')) " & _
  11. "GROUP BY JOB_PARAMETERS.JOB_ID, JOB_PARAMETERS.PARAMETER_VALUE"
  12. DoCmd.RunSQL stGetParms
Apr 6 '08 #2
NeoPa
32,556 Expert Mod 16PB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

ADMIN.
Apr 6 '08 #3

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

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
0
by: shank | last post by:
I'm trying to insert a customer profile with a stored procedure. This same code has worked on other sites. But on this site, it appears to be ignored. Nothing happens. The page loads fine with all...
0
by: ImraneA | last post by:
Hi there I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K. Wish to provide some knowledge gained back to community - hopefully help others. 1.Question how do you test stored...
3
by: celineusa | last post by:
Hello! Here is part of my database: tblStudents: StudentID tblMajorsAndStudents: StudentID, MajorID tblMajors: MajorID tblMajorsAndClasses: MajorID, ClassID, QuarterTaken tblClasses:...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
11
by: Chuck | last post by:
Can the SQL code from an Append query be inserted into the form module? The form module currently has a DoCmd Run Macro statement. The Macro opens the Append query which runs correctly. I'm trying...
3
Minion
by: Minion | last post by:
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge. First though I'll goto into the overview...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to add a long list of contacts to a group by looping...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.