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

INSERT INTO posts array item name not value into table.

5
Dear all,

I am trying to update a table with fields from an array. The array works fine, I can test it with msgboxes. However when I try to then insert the array values into a table the array the field names get pasted in instead. My code is below - any thoughts where I have gone wrong anyone?

[
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSplit_Click()
  2.     Dim MyString, MyArray, Msg
  3.         MyString = Me!txtSearch
  4.         MyArray = Split(MyString, , -1, 1)
  5.  
  6.     Dim mySQL As String
  7.         mySQL = "insert into tblSearchStock (text1, text2, text3)"
  8.         mySQL = mySQL + "values ( 'MyArray(0)', 'MyArray(1)', 'MyArray(2)')"
  9.         DoCmd.RunSQL mySQL
  10.  
  11.  
  12. End Sub
]
If I remove the ' from the MyArray(0) or use (MyArray(0)) I get an error message: 'Run time error 3085. Undefined function 'MyArray' in expression.

If I change to MyArray.Fields(0)again the field name is pasted not the field value.

Any help appreciated.
Thanks
Feb 18 '15 #1

✓ answered by jforbes

You'll want to concatenate the values of the Array into the SQL String before sending the SQL String off to the DB Engine:
Expand|Select|Wrap|Line Numbers
  1. mySQL = mySQL & " values ( '" & MyArray(0) & "', '" & MyArray(1) & "', '" & MyArray(2) & "')"

3 1436
jforbes
1,107 Expert 1GB
You'll want to concatenate the values of the Array into the SQL String before sending the SQL String off to the DB Engine:
Expand|Select|Wrap|Line Numbers
  1. mySQL = mySQL & " values ( '" & MyArray(0) & "', '" & MyArray(1) & "', '" & MyArray(2) & "')"
Feb 18 '15 #2
NeoPa
32,556 Expert Mod 16PB
Exactly.

You are working in VBA to create a string (SQL Instruction String) which is then passed on to SQL to interpret. If you bear all that in mind it's much easier to understand what should go where.
Feb 18 '15 #3
sjb67
5
Many thanks JForbes - Fantastic.

I just couldn't get that syntax right!!
Feb 19 '15 #4

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

Similar topics

5
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which...
3
by: Ruaidhri | last post by:
I want to store many different types of objects in a single table. I was thinking of using the name value pair approach to achieve this. Does anybody have any experience with a such a design? ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
6
by: Andy Sutorius via DotNetMonster.com | last post by:
Hi, What collection can I use to store name value pairs that contain duplicates in both columns? Thanks, Andy --
2
by: npverni | last post by:
I have a string with name value collections (i.e. &foo=1&foo2=2) Can I convert this string to some kind of name/value collection so I can access the values with something like : params = 1; ...
7
by: james | last post by:
Hi, I am trying to insert a record into a database table, one field of which is a byte array. Using the below: Byte imgArr; .... <code to put image into imgArr>
3
by: amolchopra | last post by:
Hello, I am using C API for MySql. From my application, I am supposed to insert a 2D array into the database table. The array can be of size 1000000 * 20. (1 million by 20). So, to accomodate this...
7
by: tarunkhatri | last post by:
Hi, I want to insert multiple rows in a database table, from an submit form. But not able to trouble shoot the problem in my code. Following is the code. <form action=test_insert.php...
1
by: gamepart | last post by:
I have an array $product_array, and when I use print_r($product_array);. The array shows like this Array ( => Array ( => P00100 => Edina => $20.00 )
4
by: bouldergirl | last post by:
I have 2 tables, Table 1 and Table 2 (see attached images)....Although in the example tables (attached), only a few records are shown, they both have about 1000 GRID values: Table 1 contains...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.