Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create temporary tables in Access

Status
Not open for further replies.

greenbird

Technical User
Jul 24, 2003
10
CA
Can anyone tell me how to create temporary tables in Access?
 
Temporary in what sense? Describe the duration of the process. Does the temporary table need to be linked to other tables etc....
 
I am trying to import Excel file into an Access table. each time i do an import, the columns from the Excel file may vary in the number of columns as well as their names. It was suggested that i use the TransferSpreadsheet function in Access using a Temporary table.

If you can suggest a solution to the original problem of importing an Excel file where the columns vary, please do so.
 
Access will automatically create a table for you. All tables are temporary. One day they'll go.

Are you asking "How do I automatically delete tables I have finished with?". I don't think Access has any specific feature to do this. You have to delete tables yourself or write code/macros to do it for you.

 
Thanks for the help.

However i am trying to import the Excel file through VBA, to make a more user friendly interface; and not through the Access menu of File, Get External Data, Import ....

Do you have any other ideas?
 
In VBA code
1. make an ADO connection to the excel spreadsheet.
2. send an SQL statement from the recordset method.
i.e. "Select * from sheeet1"
3. read the meta data returned in the recordset fields collection. Take each field name in the collection and build an SQL table create statement.
4. run the table create statement.
5. create a query to do Insert Into the access table from the excel spreadsheet table or insert record by record whichever you prefer.
i.e "Insert Into AccessTable Select * from sheet1
 
Thank you cmmrfrds for the tip. If i could let me know how to make the ADO commection to the Excel spreadsheet i would really appreciate that.
 
Check this site.

Excel uses the OLEDB provider for Microsoft Jet.

Here is an example of putting the excel data in an ADO recordset.


Public Function ReadExcel()
On Error GoTo ErrHandler
Dim cn As New ADODB.Connection, cn2 As New ADODB.Connection
Dim rs As New ADODB.Recordset, rs2 As New ADODB.Recordset
Dim connString As String, connString2 As String
Dim sql1 As String, sql2 As String
connString = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ATestDir\myTest.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
cn.ConnectionString = connString
cn.Open connString
''cn2.Open connString

Set rs.ActiveConnection = cn
'-- sheet name = newcustomers
sql1 = "select * from newcustomers"
rs.Open sql1, cn, adOpenForwardOnly, adLockReadOnly

If Not (rs.EOF = True) Then
Debug.Print "field value = "; rs.Fields(0).Value
End If

Exit Function
ErrHandler:
Dim er As ADODB.Error
Debug.Print " In Error Handler "; Err.Description
For Each er In cn.Errors
Debug.Print "err num = "; Err.Number
Debug.Print "err desc = "; Err.Description
Debug.Print "err source = "; Err.Source
Next
End Function
 
Thank you for the tip!! I will give it a try. :)
 
DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "YourNewTableName", "C:\YourDirectory\YourSpreadSheet.xls", True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top