Hi!<br><br>I need help populating an access table using VBA code only.<br>Also, how do you concatenate two fields in an access table using vba code?<br><br>Thanks,<br>Sherrie
first off, how do you want to populate the table, what is your source data.<br><br>second, to bring two fields together in one field, it depends on where you want to do it and why.<br>if you're just looking to do it to avoid having an extra query floating around, then it would just be the<br><br>docmd.runSQL " "<br><br>followed by the appropriate SQL code.<br>something like:<br><br>SELECT <font color=red>[field1]</font> & " " & <font color=red>[field2]</font> AS <font color=red>NewFieldName</font> FROM <font color=red>tablename</font>;<br><br>this even puts a space in the middle. all you have to do is put it in the quotes above, and change the red words to fit your app. <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
i'd say yes, i've used that before as well. i think i'm just on my SQL kick right now. <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
I want to populate an access table used the excel spreadsheet I imported using VBA.<br>Here's an example of excel spreadsheet table and the table I want it to populate.<br><br>F1 F2 F3 F4 F5 F6 F7<br><br>1 Diagnosis Anxiety 300.00 xx 930 49006<br><br>Form Element Table:<br><br>FormID Order ElemGroup ElemName ElemVal ElemType CodeMeth ChargeCode <br><br>0001 1 Diagnosis Anxiety 300.00 xx 930<br>49006<br><br>I want to add F6+F7 before importing to the form element table, output should be: 93049006 (chargecode)<br> <br>Thanks,<br>Sherrie<br>
personally, i don't know if there is a way to import it directly into a table and combine those two fields from Excel (i'm sure there has to be a way though). You could just import the table as is, and then run a Make Table query that concatenates the two fields using any of the code above. <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
Assuming you have already imported the Excel data and that F1-F7 are the fieldnames in the imported table... then a "append" query is all you need.<br><br>You probably will want to make a copy of your "Form Element" table before you start, in case something doesn't work while testing. <br><br>Start a new query and add your imported table to the upper section of the query designer. Change the query type to Append. This will ask you for the name of the table to append the new records to. Enter the name of your "Form Element" table.<br><br>Then select all the columns from your imported table and drop them on the grid in the lower half.<br><br>Select the column names to receive the data into the "append to" row of the grid.<br><br>Delete F6 and F7 columns. Type a formula into an empty space... "[F6] & [F7]" (do not type the quotes).<br><br>Select "ChargeCode" for the "AppendTo" row of the grid.<br><br>Running the query will append the rows. <p>Jim Conrad<br><a href=mailto:JimConrad@Consultant.com>JimConrad@Consultant.com</a><br><a href= > </a><br>
Thanks Guys,<br><br>It works using the query. But I have to use VBA code only.<br>But I figured it out.<br><br>Here's the code for future references:<br><br>'This module selects all records in the Excel Import File table and copies them into the<br>'form elements table.<br><br>Sub SelectIntoX()<br><br> Dim db As Database<br> Dim qdf As QueryDef<br><br> Set db = CurrentDb<br> <br>'Selects all records in the Import table and adds F6 & F7 from the excel file called "spreadsheet" and copies the fields into a new table, "FormElemen_Backup".<br> <br>db.Execute "SELECT Spreadsheet.F1, Spreadsheet.F2, Spreadsheet.F3, Spreadsheet.F4,spreadsheet.F5, [F6] & [F7] AS ChargeCode INTO " _<br>& "[Formelem_back] FROM Spreadsheet;"<br> <br> ' Delete the old table<br> 'db.Execute "DROP TABLE [spreadsheet];"<br> <br>db.Close<br><br>End Sub<br><br><br>Sherree
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.