Previous Thread

8/2/2006 7:15:42 PM    Problem with DAO (Import from Excel to Access)! :(
Hi, 
 
I am novice and I have problem. I need import some data with Excel file 
 
to Access. 
 
Problem introduces as follows: 
 
In Excel(first sheet) i have data: 
 
"TYTUL" - column "A" 
 
"NAZWISKO" - column "B" 
 
"IMIE" - column "C" 
 
"PRZEDMIOT" - column "D". 
 
Excel file name is AND.xls 
 
In Access i have table - AS_PRZEDMIOT. 
 
Table "AS_PRZEDMIOT" contains fields: 
 
ID_PRZEDMIOT (Auto), 
 
P_AKTYWNY (Number), 
 
P_ID_GRUPA (Number), 
 
P_ID_KATEDRA (Number), 
 
P_ID_KIERUNEK (Number), 
 
P_NAZWA (String), 
 
P_NAZWA_0 (String), 
 
P_NAZWA01 (String), 
 
P_SKROT (String), 
 
P_UWAGI (String) 
 
UPDATE_DATE (Number), 
 
UPDATE_USER (String), 
 
P_SKROT_0 (String), 
 
P_SKROT_01 (String). 
 
I need import data from Excel (PRZEDMIOTY - column "D") to Access (field 
 
P_NAZWA). Additionally to every record in field P_AKTYWNY insert number "1". 
 
How to do? 
 
I try in support about example modules VBA (in Accesss): 
 
but I do not know how to modify (use) this code? 
 
How to make this the best? 
 
Sub Test(Tabela_rs As String) 
 
Dim rs As DAO.Recordset 
 
Dim rd As DAO.Recordset 
 
Set rs = CurrentDb.OpenRecordset(Tabela_rs, dbOpenSnapshot) 
 
Set rd = CurrentDb.OpenRecordset("AS_Przedmiot") 
 
rs.MoveFirst 
 
While Not rs.EOF 
 
rd.AddNew 
 
'rd![ID_PRZEDMIOT] = rs![ID_PRZEDMIOT] 
 
rd![P_NAZWA] = rs![P_NAZWA] 
 
' ..... 
 
rd.Update 
 
rs.MoveNext 
 
Wend 
 
End Sub 
 
Sub StartTest() 
 
Test ("AS_Przedmiot") 
 
MsgBox "sukces" 
 
End Sub 
 
Kind Regards, 
 
Andrzej.



8/3/2006 10:13:42 AM    Re: Problem with DAO (Import from Excel to Access)! :(
hi And1, 
 
And1 wrote: 
 
You can use 
 
INSERT INTO [AS_PRZEDMIOT] ([P_NAZWA]) 
 
SELECT [PRZEDMIOTY] 
 
FROM [Excel 8.0;Database=YourExcel;Hdr=Yes].[NameOfSheet$] 
 
as SQL statement in an ordenary query. 
 
mfG 
 
--> stefan <--