473,472 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can not pass variable value to insert into statement

14 New Member
Hi new to the forum and visual basic.

I am attempting to fix a migration of excel to access. The excel sheets where simple copied as is into access. for example one table lists the academic history from elementary to phd and on to post doctoral work alll on the same row. I want to break that up to have each level of education as a seperate record and then relate that back to the person.

i can pull the data into a recordset
I can iterate through it by row and column and place the data into an array

from there I was going to simple insert the data into a table with new metadata.

One row for each level of education, but I can not pass the array value back to the database. It recognized the variable names literally or as functions i.e. as "edu(0) = function not array variable or undefined as the variable is not surrounded with quotes.

I thougth is should just declair a command object e.g. objcmd as new command,
define the command txt e.g. objcmd.commandtext = "insert into table (field, field) values (edu(0),edu(1))",
and then execute the command e.g. objcmd.execute

but the value is either not defined or is considered a function. It works if I put in literal values like "test" or 1234 ,but not with variables. How do I pass back to the DB. the values I got from it via recordset?

any help is greatly appreciated.
Jul 26 '07 #1
5 5732
Killer42
8,435 Recognized Expert Expert
Hi. Welcome to the forum.

What you need to do is insert the values of the variables into the SQL statement, not their names. With single quotes around them if they are strings, of course.

For example...
Expand|Select|Wrap|Line Numbers
  1. objcmd.commandtext = "insert into table (field, field) values " _
  2.   & "('" & edu(0) & "', '" & edu(1) & "')"
Jul 26 '07 #2
techbuddha
14 New Member
Hi. Welcome to the forum.

What you need to do is insert the values of the variables into the SQL statement, not their names. With single quotes around them if they are strings, of course.

For example...
Expand|Select|Wrap|Line Numbers
  1. objcmd.commandtext = "insert into table (field, field) values " _
  2.   & "('" & edu(0) & "', '" & edu(1) & "')"

Hi thanks for the quick reply :-) One question would the Docmd.runSql give me the same results? given that I make the same changes to the sql statement you mentioned above?

thanks a bunch
Jul 26 '07 #3
techbuddha
14 New Member
Hi thanks for the quick reply :-) One question would the Docmd.runSql give me the same results? given that I make the same changes to the sql statement you mentioned above?

thanks a bunch

sorry nevermind I guess I should just try it. Thanks again for the help
Jul 26 '07 #4
Killer42
8,435 Recognized Expert Expert
sorry nevermind I guess I should just try it. Thanks again for the help
How did it turn out?
Jul 27 '07 #5
techbuddha
14 New Member
works great! thanks alot
Jul 31 '07 #6

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

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
8
by: eleftheriak | last post by:
Hi All, I have the following code. i m wondering how you pass the actual value of a variable to an insert query I want to input the value os jobnumber and finalstring strSqlEmail1 =...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
10
by: tshad | last post by:
I want to access multiple arguments based on name passed. For example I have the following asp:textboxes: BillingAddress1 BillingAddress2 BillingCity ShippingAddress1 ShippingAddress2...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
6
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.