MS Access Forum / General 1 / May 2008
Only two options to import Excel files?
|
|
Thread rating:  |
PW - 20 May 2008 04:18 GMT Convert them to CSV in Excel, then use TransferText (which does not work correctly and also doesn't accept XLS/Excel files directly) or create a link to an Excel XLS workbook and do an Append Query (as some have suggested here)??
I find that hard to believe as Access is part of MS Office and Visual FoxPro is not. I split my time using both and I can do a simple copy command to XLS in VFP or an Append command to DBF or use Office Automation to build workbooks using VFP with ease. I've been doing this for years.
TransferText is incorrectly transposing some information as blank fields (seems like a crap shoot). I don't know what the CSV (wish it could be an XLS) file is until I return the file name and path from a user dialog box that selects the file.
-pw
lyle fairfield - 20 May 2008 04:27 GMT Is there a question here?
On May 19, 11:18 pm, PW <paulremove_williamson...@removehotmail.com> wrote:
> Convert them to CSV in Excel, then use TransferText (which does not > work correctly and also doesn't accept XLS/Excel files directly) or [quoted text clipped - 13 lines] > > -pw PW - 20 May 2008 04:44 GMT >Is there a question here? Do I have any other options????
-pw
>On May 19, 11:18 pm, PW <paulremove_williamson...@removehotmail.com> >wrote: [quoted text clipped - 15 lines] >> >> -pw PW - 20 May 2008 04:52 GMT >Is there a question here? For instance, is there any command like this in Access 2003. This is from Visual FoxPro8 which has been bashed for years but yet as not part of the MS Office suite and not part of Visual Studio can still transfer data to and from Excel with ease (and to a DBF file)!:
Adds records to the end of the currently selected table from another file.
APPEND FROM FileName | ? [FIELDS FieldList] [FOR lExpression] [[TYPE] [DELIMITED [WITH Delimiter | WITH BLANK | WITH TAB | WITH CHARACTER Delimiter] | DIF | FW2 | MOD | PDOX | RPD | SDF | SYLK | WK1 | WK3 | WKS | WR1 | WRK | CSV | XLS | XL5 [SHEET cSheetName] | XL8 [SHEET cSheetName]]] [AS nCodePage] Parameters FileName Specifies the name of the file to append from. If you don't include a file name extension, a Visual FoxPro table and a default extension .dbf is assumed. If you are appending from a Visual FoxPro table, records in the table that are marked for deletion are appended if the current SET DELETED setting is OFF. ? Displays the Open dialog box, from which you can choose a table to append from. FIELDS FieldList Specifies to which fields data is appended. FOR lExpression Appends a new record for each record in the currently selected table for which lExpression evaluates to True (.T.). Records are appended until the end of the currently selected table is reached. If you omit FOR, the entire source file is appended to the currently selected table. TYPE Specifies the source file type of the file you are appending from. Although you must specify a file type if the file you are appending from isn't a Visual FoxPro table, you need not include the TYPE key word. You can append from a wide variety of different file types including delimited ASCII text files, in which you can specify a field delimiter. If the source file you are appending from doesn't have the usual default file extension for that type of file, the source file name must include the file's extension. For example, Microsoft Excel worksheets normally have an .xls extension. If the Microsoft Excel worksheet you append from has an extension other than the expected .xls, be sure to specify the extension.
Note When you are appending from a worksheet, the data in the worksheet must be stored in a row-major order rather than a column-major order. This allows the appended worksheet data to match the table structure. DELIMITED Specifies that the source file from which data is appended to the current Visual FoxPro table is a delimited file. A delimited file is an ASCII text file in which each record ends with a carriage return and line feed. Field contents are by default assumed to be separated from each other by commas (do not include extra spaces before or after the commas), and character field values to be additionally delimited by double quotation marks. For example: "Smith",9999999,"TELEPHONE" The file extension is assumed to be .txt for all delimited files.
You can import dates from delimited files if the dates are in proper date format. The date format defaults to mm/dd/yy. Including the century portion of a date is optional. Visual FoxPro will import a date, such as 12/25/95, that doesn't include the century and assumes the date is in the twentieth century. Date delimiters can be any non-numeric character except the delimiter that separates the fields in the delimited file.
Dates in other formats can be imported if their formats match date formats available in SET DATE. To import dates that are not in the default format, issue SET DATE with the proper date format before using APPEND FROM. To test whether a date format can be successfully imported, use it with CTOD( ). If the date is acceptable to CTOD( ), the date will import properly.
DELIMITED WITH Delimiter Indicates that character fields are separated by a character other than the quotation mark. DELIMITED WITH BLANK Specifies files that contain fields separated by spaces instead of commas. DELIMITED WITH TAB Specifies files that contain fields separated by tabs rather than commas. DELIMITED WITH CHARACTER Delimiter Specifies files that contain fields all enclosed by the character specified with Delimiter. If Delimiter is a semicolon (the character used in Visual FoxPro to indicate command line continuation), enclose the semicolon in quotation marks. You can also specify the BLANK and TAB keywords for Delimiter. The WITH Delimiter clause can be combined with the WITH CHARACTER clause. For example, the following command adds records from a text file with character fields enclosed by underscores and all fields delimited from each other with asterisks:
APPEND FROM mytxt.txt DELIMITED WITH _ WITH CHARACTER * DIF Include DIF to import data from a VisiCalc .dif (Data Interchange Format) file. Vectors (columns) become fields in the currently selected table and tuples (rows) become records. DIF file names are assumed to have a .dif extension. FW2 Include FW2 to import data from a file created by Framework II. FW2 file names are assumed to have a .fw2 extension. MOD Include MOD to import data from a Microsoft Multiplan version 4.01 file. MOD files are created by Microsoft Multiplan version 4.01, and are assumed to have a .mod extension. PDOX Include PDOX to import data from a Paradox version 3.5 or 4.0 database file. Paradox file names are assumed to have a .db extension. RPD Include RPD to import data from a file created by RapidFile version 1.2. RapidFile file names are assumed to have an .rpd extension. SDF Include SDF to import data from a System Data Format file. An SDF file is an ASCII text file in which records have a fixed length and end with a carriage return and line feed. Fields are not delimited. The file name extension is assumed to be .txt for SDF files. Effective conversion of date data from SDF files to Visual FoxPro tables requires data to be stored in YYYYMMDD format.
If date information is stored in ambiguous formats, you should map the date column to a character column of appropriate width so you can inspect the value then apply the correct conversion routine to create correctly formatted date data.
SYLK Include SYLK to import data from a SYLK (Symbolic Link) interchange format file. SYLK files are used in Microsoft MultiPlan. Columns in the SYLK file become fields in the Visual FoxPro table and rows become records. SYLK file names have no extension. WK1 Include WK1 to import data from a Lotus 1-2-3 version 2.x spreadsheet. Each column from the spreadsheet becomes a field in the table; each spreadsheet row becomes a record in the table. A .WK1 file name extension is assigned to a spreadsheet created in Lotus 1-2-3 revision 2.x. WK3 Include WK3 to import data from a Lotus 1-2-3 spreadsheet. Each column from the spreadsheet becomes a field in the table; each spreadsheet row becomes a record in the table. A .wk3 file name extension is assigned to a spreadsheet created in Lotus 1-2-3 revision 3.x. WKS Include WKS to import data from a Lotus 1-2-3 revision 1-A spreadsheet. Each column from the spreadsheet becomes a field in the table; each spreadsheet row becomes a record in the table. A .wks file name extension is assigned to a spreadsheet created in Lotus 1-2-3 revision 1-A. WR1 Include WR1 to import data from a Lotus Symphony version 1.1 or 1.2 spreadsheet. Each column from the spreadsheet becomes a field in the table and each spreadsheet row becomes a record in the table. A .wr1 file name extension is assigned to a spreadsheet created in Symphony versions 1.1 or 1.2. WRK Include WRK to import data from a Lotus Symphony version 1.0 spreadsheet. Each column from the spreadsheet becomes a field in the table and each spreadsheet row becomes a record in the table. A .wrk file name extension is assigned to a spreadsheet created in Symphony version 1.0. CSV Include CSV to import data from a comma separated value file. A CSV file has field names as the first line in the file; the field names are ignored when the file is imported. XLS Include XLS to import data from a Microsoft Excel worksheet. Each column from the worksheet becomes a field in the table and each worksheet row becomes a record in the table. Worksheet files created in Microsoft Excel are given an .xls file name extension. XL5 Include XL5 to import data from Microsoft Excel version 5.0. Columns from the worksheet become fields in the table; the worksheet rows become records in the table. Worksheet files created in Microsoft Excel have an .xls extension. If you omit the SHEET clause, the data in Sheet1 is imported. To import data from a specific sheet, include the SHEET keyword and specify the sheet name with cSheetName.
XL8 Include XL8 to import data from Microsoft Excel 97. Columns from the worksheet become fields in the table; the worksheet rows become records in the table. Worksheet files created in Microsoft Excel have an .xls extension. If you omit the SHEET clause, the data in Sheet1 is imported. To import data from a specific sheet, include the SHEET keyword and specify the sheet name with cSheetName.
AS nCodePage Specifies the code page of the source table or file. Visual FoxPro copies the contents of the source table or file and, as it copies the data, automatically converts the data to the code page of the current table. If you specify a value for nCodePage that is not supported, Visual FoxPro generates an error message. You can use GETCP( ) for nCodePage to display the Code Page dialog box, making it possible for you to specify a code page for the appended table or file.
If you omit AS nCodePage and Visual FoxPro cannot determine the code page of the source table or file, Visual FoxPro copies the contents of the source table or file. As it copies the data, it automatically converts the data to the current Visual FoxPro code page. If SET CPDIALOG is ON, the table in the currently selected work area is marked with a code page. If you're appending from a table not marked with a code page, the Code Page dialog is displayed, making it possible for you to choose the code page of the table from which you're appending. The current Visual FoxPro code page can be determined with CPCURRENT( ).
If you omit AS nCodePage and Visual FoxPro can determine the code page of the table or file being appended, Visual FoxPro copies the contents of the appended table or file. As it copies the data, it automatically converts the data to the code page of the currently selected table.
If nCodePage is 0, Visual FoxPro assumes that the code page of the table or file being appended is the same as the code page of the currently selected table. No conversion to the current Visual FoxPro code page occurs.
Remarks If the file from which you append is a Visual FoxPro table or a table created in an earlier version of FoxPro, a .dbf extension is assumed. If the Visual FoxPro table or the table created in an earlier version of FoxPro doesn't have a .dbf extension, you must specify its extension. If the file is not a Visual FoxPro table or a table created in an earlier version of FoxPro, you must specify the type of file from which you append.
Before you can append from a table created in dBASE IV or dBASE V that contains a memo field, you must first open the table in Visual FoxPro with USE. When you are prompted to convert the file, choose Yes.
If you append from a Visual FoxPro table or a table created in an earlier version of FoxPro, the table you append from can be open in another work area. Records marked for deletion in the table you are appending from are unmarked once the records are appended.
Use the DBF( ) function to append from a temporary read-only cursor created by a SELECT - SQL command. Include the name of the cursor in the DBF( ) function as in the following example:
APPEND FROM DBF('<Cursor Name>') If the target table uses autoincrementing, APPEND FROM fails if AUTOINCERROR is set to ON, unless the FIELDS option is used to omit the AUTOINC column. Setting AUTOINCERROR to OFF or turning off autoincrementing in the target table by using CURSORSETPROP( ) allows the APPEND FROM to succeed. The target table's autoincrementing field or fields are incremented according to the values specified, and the values in source table are not applied.
Example In the following example, the customer table is opened, its structure is copied to a table called backup, and backup is then opened. Visual FoxPro then appends all records from Finland from the customer table. These records are then copied to a new delimited file called TEMP.TXT.
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customer && Open customer table COPY STRUCTURE TO backup USE backup APPEND FROM customer FOR country = 'Finland' COPY TO temp TYPE DELIMITED MODIFY FILE temp.txt USE DELETE FILE backup.dbf DELETE FILE temp.txt See Also COPY FILE | COPY TO | EXPORT | GETCP( ) | IMPORT | SET DELETED
>On May 19, 11:18 pm, PW <paulremove_williamson...@removehotmail.com> >wrote: [quoted text clipped - 15 lines] >> >> -pw Sky - 20 May 2008 15:47 GMT > For instance, is there any command like this in Access 2003. This is > from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 3 lines] > Adds records to the end of the currently selected table from another > file. Here is some sample SQL for a query to insert records into an Access table named MyAccessTable from an Excel file named C:\Sample\MyExcelFile.xls:
INSERT INTO MyAccessTable (FieldA, FieldB) SELECT FieldA, FieldB FROM [Excel 8.0;HDR=YES;IMEX=2;DATABASE=C:\Sample\MyExcelFile.xls].[MyExcelWorksheet];
You can do similar things with text files or dBase files.
- Steve
PW - 20 May 2008 19:51 GMT >> For instance, is there any command like this in Access 2003. This is >> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 13 lines] > >- Steve Nice Steve! I will try that tomorrow. I assume I create an Access table first so I can have field names?
-paul
Sky - 20 May 2008 20:40 GMT >>> For instance, is there any command like this in Access 2003. This is >>> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 19 lines] > > -paul You can append to an existing table, or create a make-table query directly from Excel, just like from any other data source. Of course, I never recommend make-table queries in production, since you do not get precisely defined field specifications, key fields, indexes, etc.
- Steve
PW - 21 May 2008 23:14 GMT >> For instance, is there any command like this in Access 2003. This is >> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 13 lines] > >- Steve Not working for me. Access doesn't like tblTempCashReg. Syntax error:
Insert into rstTempCashReg(manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) Select manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail From [Excel8.0;HDR=YES;IMEX=2;DATABASE= strReturnVal].[Sheet1]
lyle fairfield - 22 May 2008 00:56 GMT I don't like using recordsets but in cases where the import is gnarly, they can let one proceed a step at a time, first establishing a connection, then populating the recordset, then modifying the data, and finally, inserting it into a table. The code can be written and tested bit by bit.
I had three ways of doing what this code does, and can actually remember one of the others, which was to link to the Excel file through SQL-Server.
Option Base 0 Option Compare Database Option Explicit
Sub UploadDataFromOfficialProjectedEnrolment(ByVal ExcelFilePath$, ByVal ExclusivelyFrenchImmersion$, ByVal LateFrenchImmersion$) Dim LocalConnection As ADODB.Connection Dim Enrolment& Dim PreviousSchoolName$ Dim ProgramID Dim SchoolsAndEnrolment As ADODB.Recordset Dim SchoolID& Dim SchoolNameField As ADODB.Field Dim SchoolName$ Dim SQL$ Dim Areas$(0 To 2) Dim y& Dim z&
'-----------------
ExclusivelyFrenchImmersion = "," & Trim(ExclusivelyFrenchImmersion) & "," LateFrenchImmersion = "," & Trim(LateFrenchImmersion) & ","
'-----------------
Set LocalConnection = New ADODB.Connection With LocalConnection .Provider = "Microsoft.Jet.OLEDB.4.0" .Properties.Item("Data Source") = ExcelFilePath .Properties.Item("Extended Properties") = "Excel 8.0" .Open End With
'-----------------
Areas(0) = "EAST$" Areas(1) = "NORTH$" Areas(2) = "WEST$"
SQL = "DELETE FROM Schools" CurrentProject.Connection.Execute (SQL)
SQL = "SELECT * FROM [AREA]" SQL = SQL & vbNewLine SQL = SQL & "WHERE [School Name] IS NOT NULL" SQL = SQL & vbNewLine SQL = SQL & "AND [School Name] <> 'Total'" SQL = SQL & vbNewLine SQL = SQL & "AND [School Name] <> 'Grand Total'" SQL = SQL & vbNewLine SQL = SQL & "AND [F14] IS NOT NULL"
For y = 0 To 2 Set SchoolsAndEnrolment = LocalConnection.Execute(Replace(SQL, "AREA", Areas(y))) With SchoolsAndEnrolment Set SchoolNameField = .Fields(0) While Not .EOF SchoolName = StrConv(Replace(Trim(SchoolNameField.Value), "'", ""), vbUpperCase) If Len(SchoolName) > 0 And InStr(SchoolName, "TOTAL") = 0 Then ProgramID = 2 If (PreviousSchoolName = SchoolName) And (InStr(LateFrenchImmersion, "," & SchoolName & ",") <> 0) Then ProgramID = 3 If PreviousSchoolName <> SchoolName Then CurrentProject.Connection.Execute "INSERT INTO Schools ([Name]) VALUES ('" & Replace(SchoolName, "'", "") & "')" SchoolID = CurrentProject.Connection.Execute("SELECT @@Identity")(0) If InStr(ExclusivelyFrenchImmersion, "," & SchoolName & ",") = 0 Then ProgramID = 1 PreviousSchoolName = SchoolName End If For z = 1 To 11 Enrolment = Nz(.Fields(z).Value, 0) If Enrolment > 0 Then CurrentProject.Connection.Execute _ "INSERT INTO Enrolments (School, Program, Class, Enrolment) VALUES (" _ & SchoolID & "," & ProgramID & "," & z & "," & Enrolment & ")" End If Next z End If .MoveNext Wend End With Next y
MsgBox "All Done Uploading Schools and Enrolment", vbInformation, "ffdba" On Error Resume Next DoCmd.Close acForm, "UploadNewSchoolData"
End Sub
On May 21, 6:14 pm, PW <paulremove_williamson...@removehotmail.com> wrote:
> On Tue, 20 May 2008 14:47:31 GMT, "Sky" <sky @ stanley associates . > Not working for me. Access doesn't like tblTempCashReg. Syntax PW - 22 May 2008 04:03 GMT What do the $ and & mean Lyle?
I am not using SQL Server, just an Access front and backend.
Thanks,
-paul
>I don't like using recordsets but in cases where the import is gnarly, >they can let one proceed a step at a time, first establishing a [quoted text clipped - 110 lines] >> On Tue, 20 May 2008 14:47:31 GMT, "Sky" <sky @ stanley associates . >> Not working for me. Access doesn't like tblTempCashReg. Syntax PW - 22 May 2008 04:18 GMT Lyle and Steve, I love your code!. And thanks so much for your help!
Guys, all I am trying to do is to come up with an equivalent in VBA for this simple line of code that I do in Visual FoxPro about every day (you should see the stuff I do with Office Automation and Excel, Word,...with Visual FoxPro! I guess I just bragged - sorry about that!;-):
Use tblImpData Select tblImpData_pw Append From k:\AttributionData\IMPORTDATA\chase.xls type XLS
Bingo! Batta Bing! That's all it takes. Show me that it can happen in Access!! Don't mean to start a war here between Access and Visual FoxPro. I love them both, but come on now!
VFP is not part of MS Office or Visual Studio so how come VFP can do this so easily and appears impossible in Access (which is part of Office)???????????????
The app's front end/mde is in Access 2003 and the backend mdb is separated also in Access 2003. I need this for a distrubited mde so we are not on site and do not have Access running.
-paulw
>I don't like using recordsets but in cases where the import is gnarly, >they can let one proceed a step at a time, first establishing a [quoted text clipped - 110 lines] >> On Tue, 20 May 2008 14:47:31 GMT, "Sky" <sky @ stanley associates . >> Not working for me. Access doesn't like tblTempCashReg. Syntax Sky - 22 May 2008 02:32 GMT >>> For instance, is there any command like this in Access 2003. This is >>> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 23 lines] > manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail > From [Excel8.0;HDR=YES;IMEX=2;DATABASE= strReturnVal].[Sheet1] Is rstTempCashReg the name of a table? The prefix indicates a recordset name.
Also there is no space after rstTempCashReg and before the parenthesis.
And is "strReturnVal" the literal name of an Excel spreadsheet file? It should end with .xls. If it is a string, then you need to concatenate it with the SQL as a string.
Can you make a simple Select query from Excel, such as the following SQL?:
Select manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail From [Excel8.0;HDR=YES;IMEX=2;DATABASE= YourSpreadsheetName.xls].[Sheet1]
If you CAN see the Select query datasheet, then you know you have an error in the "Insert Into" part of the query.
If you CANNOT see the Select query datasheet, then you need to check the Select part with your Excel file name.
But offhand, it looks like none of the names are correct, and you have some debugging to do.
- Steve
PW - 22 May 2008 03:45 GMT >>>> For instance, is there any command like this in Access 2003. This is >>>> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 49 lines] > >- Steve I am getting a "Cannot find installable ISAM" message in Access with this code in SQL view when I try to run it:
Select manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail From [Excel8.0;HDR=YES;IMEX=2;DATABASE= C:\SD\Access2003\Lodgeical\clientversions\JoshuaCreek\cashregister20080501.xls].[Sheet1]
The code will not save in the editor to begin with. It is in Red.
Thanks,
-pw
PW - 22 May 2008 03:53 GMT >>>> For instance, is there any command like this in Access 2003. This is >>>> from Visual FoxPro8 which has been bashed for years but yet as not [quoted text clipped - 49 lines] > >- Steve Here is most of the code Steve (I did comment out yours). I also tried Select * (Wildcard) but am not sure that works with Access 2003.
Again, the code won't even save in Access. And I have a dialog box where the user selects a CSV file but also tried hardcoding an XLS file:
Private Sub cmdImport_pw_Click()
Dim strFilePart1 As String, strFilePart2 As String, strFileName As String Dim strFilter As String, strReturnVal As String Dim strFind As String, strBarCode As String Dim lngStrLength As Long Dim intPurchaser As Integer, intInventoryID As Integer Dim varFileDate As Variant, varReturnVal As Variant
Dim dbCurr As Database Dim rstTempCashReg As Recordset Dim rstPurchases As Recordset Dim rstInventory As Recordset
Set dbCurr = CurrentDb
Set rstTempCashReg = dbCurr.OpenRecordset("tblTempCashReg") Set rstPurchases = dbCurr.OpenRecordset("tblInventoryPurchases") Set rstInventory = dbCurr.OpenRecordset("tblInventory")
' Display a dialog box for the user to point to the Excel file (note: must be in CSV format and in yyyymmdd order):
strFilter = ahtAddFilterItem(strFilter, "Comma Seperated Value Files (*.csv)", "*.CSV") 'strFilter = ahtAddFilterItem(strFilter, "Comma Seperated Value Files (*.xls)", "*.xls")
strReturnVal = ahtCommonFileOpenSave(Filter:=strFilter, _ OpenFile:=True, _ DialogTitle:="Please select the document...", _ Flags:=ahtOFN_HIDEREADONLY)
' Drop the path, only need the file name:
strFileName = Mid$(strReturnVal, InStrRev(strReturnVal, "\") + 1)
' Separate the text part from the date part:
strFilePart1 = Left(strFileName, Len(strFileName) - 12) strFilePart2 = Format(Val(Right(strFileName, 12)), "00000000")
' Convert the date part (must be yyyymmdd to date format:
varFileDate = DateSerial(Left(strFilePart2, 4), Mid(strFilePart2, 5, 2), Right(strFilePart2, 2))
' Make sure purchases have not already been recorded for that date:
intPurchaser = 1643 strFind = "[date] = #" & varFileDate & "# And [purchaser] = " & intPurchaser
varReturnVal = DLookup("[date]", "tblInventoryPurchases", strFind)
If Not IsNull(varReturnVal) Then MsgBox "Cash Register Purchases have already been imported for this date." GoTo ExitImportSub End If
' Delete the records in the work file:
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete Distinctrow [tblTempCashReg].* From [tblTempCashReg]"
DoCmd.SetWarnings True
' Populate the work file:
'Insert into tblTempCashReg '(manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) 'Select 'manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail 'From [Excel8.0;HDR=YES;IMEX=2;DATABASE= strReturnVal].[Sheet1]
DoCmd.TransferText acImportDelim, , "tblTempCashReg", strReturnVal, -1
If rstTempCashReg.RecordCount = 0 Then MsgBox "There were no records to import." GoTo ExitImportSub End If
PW - 22 May 2008 17:31 GMT The syntax you supplied (I copied and pasted it on one line):
INSERT INTO MyAccessTable (FieldA, FieldB) SELECT FieldA, FieldB FROM [Excel 8.0;HDR=YES;IMEX=2;DATABASE=C:\Sample\MyExcelFile.xls].[MyExcelWorksheet]
generates "compile error: expected end of statement" when I move the cursor out of that line.
-pw
PW - 22 May 2008 17:41 GMT strSQL = "Insert into tblTempCashReg (manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) Select manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail From [Excel8.0;HDR=YES;IMEX=2;DATABASE= strReturnVal].[Sheet1]"
DoCmd.RunSQL strSQL
Generates "could not find installable ISAM"
-pw
Salad - 22 May 2008 18:24 GMT > strSQL = "Insert into tblTempCashReg > (manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) [quoted text clipped - 7 lines] > > -pw What is ;Database= strReturnVal? Is strReturnVal a new Access keyword? Does Access like spaces in the string defining the source?
Before you even get into Inserting why don't you simply attempt to get the Select query working first?
Get into the QBE, (Query/Design/New/Cancel) and select View/SQL from the menu and paste the Select SQL into it and run and debug.
Last Dance http://www.youtube.com/watch?v=WdTYcnUBADw
PW - 22 May 2008 18:31 GMT >> strSQL = "Insert into tblTempCashReg >> (manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) [quoted text clipped - 9 lines] >What is ;Database= strReturnVal? Is strReturnVal a new Access keyword? > Does Access like spaces in the string defining the source? You're right - it's a syntax thing. This string stuff always drives me up the wall! :-)
I am still messing with it, trying to get rid of the apostrophe,....
? strReturnVal
C:\SD\Access2003\Lodgeical\clientversions\JoshuaCreek\cashregister20080501.xls
?strSQL
Insert into tblTempCashReg (manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) Select manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail From [Excel8.0;HDR=YES;IMEX=2;DATABASE= 'C:\SD\Access2003\Lodgeical\clientversions\JoshuaCreek\cashregister20080501.xls']
I've gotten it down to "you can not import this file" <s>
>Before you even get into Inserting why don't you simply attempt to get >the Select query working first? Will do. Am trying to!
>Get into the QBE, (Query/Design/New/Cancel) and select View/SQL from the >menu and paste the Select SQL into it and run and debug. Thanks!
Salad - 22 May 2008 20:02 GMT >>> strSQL = "Insert into tblTempCashReg >>>(manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) [quoted text clipped - 40 lines] > > Thanks! Heres a routine that might help. First, do a File/GetExternalData/Link to the spreadsheet. Now create a new code module and drop this code into it.
Public Function MyConnect() As Long Dim tdf As TableDef Dim dbs As Database Set dbs = CurrentDb Set tdf = dbs.TableDefs("YourSpreadsheetName")
MsgBox tdf.Connect Debug.Print tdf.Connect
dbs.Close Set dbs = Nothing End Function
In the Immediate window you'll have the connect string. It appears you don't want to link this spreadsheet so by having the correct string you can at least get close to what you want.
After you link, create your query and see if that works. Heck, it might even be easier for you to link the spreadsheet, run a query on it, then delete the link. You've spent a while on this problem. Time to figure it out and move on to other things.
Math Club http://www.youtube.com/watch?v=3r2C_4dwPh8
PW - 22 May 2008 20:23 GMT >>>> strSQL = "Insert into tblTempCashReg >>>>(manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) [quoted text clipped - 65 lines] >even be easier for you to link the spreadsheet, run a query on it, then >delete the link Looks fantastic!
> You've spent a while on this problem. No kidding! And I am hardly making a $ on it (it's a request from one of our clients) but it's worth it as I learned alot from every one here.
>Time to figure >it out and move on to other things. I just did. After all this, I just discovered the transferspreadsheet function! LOL!
DoCmd.TransferSpreadsheet acImport, , "tblTempCashReg", strReturnVal, -1
It works with the return value of the path to the spreadsheet. Except, Excel is listing a bar code text box with values like 6.17867e+011 for some reason and that is what is getting imported to the table. I can put the blame on the client and have them fix it.
Thanks for everyone's help!
-paul
>Math Club >http://www.youtube.com/watch?v=3r2C_4dwPh8 CDMAPoster@fortunejames.com - 22 May 2008 21:16 GMT On May 22, 12:41 pm, PW <paulremove_williamson...@removehotmail.com> wrote:
> strSQL = "Insert into tblTempCashReg > (manufacturer,description,barcode,color,styleormodel,size,qty,oldplu,cost,retail) [quoted text clipped - 7 lines] > > -pw That's exactly what I would expect. In:
http://groups.google.com/group/comp.databases.ms-access/msg/16e5554ab679a9ce
I said:
"A2K dropped the Isam capability to link the FoxPro tables"
James A. Fortune CDMAPoster@FortuneJames.com
|
|
|