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

Excel file upload or import into Access

24
Hello to all, can anyone please help in how to import the excel file into Access through VB Code. I have written a prog. but i m getting error as "Sntax Error in From Clause"
Aug 4 '07 #1
11 6051
hariharanmca
1,977 1GB
Hello to all, can anyone please help in how to import the excel file into Access through VB Code. I have written a prog. but i m getting error as "Sntax Error in From Clause"
Can you explain little bit more. and what you had tryed till now?
Aug 4 '07 #2
lucky13
24
Can you explain little bit more. and what you had tryed till now?
Thanks for shwoing intrest in my question, below i m mentioning the code which i wrote, which help u to solve my proble ;

Private Function UploadExcel() As Boolean

On Error GoTo Err

Dim rstemp As New ADODB.Recordset
Dim rsupload As New ADODB.Recordset
Dim rssrno As New ADODB.Recordset
Dim objexcel As Object
Dim strsql As String
Dim strfilename As String
Dim intcount As Integer, x As Long
Dim strfname As String, strlname As String, strsrno As String

conn.Open
'cn.Open
rsupload.CursorLocation = adUseClient
rstemp.CursorLocation = adUseClient
rssrno.CursorLocation = adUseClient
' UploadExcel = False

'strfilename = frmInputBox.InputString("Select upload file", "Upload File...", "", , "xls")
'strfilename = InputBox("Select excel file for Upload", "Upload File...", "", "xls")
'strfilename = InputBox("Select upload file", "Upload File...", "", , "xls") 'PLEASE CHECK THE PARAMETER SEQUENCE

strfilename = InputBox("Select Upload File", "Upload Files....", "")


MsgBox "File Uploading Started", vbOKOnly + vbInformation, "Uploading"

If Trim(strfilename) <> "" Then
Screen.MousePointer = vbHourglass

Set objexcel = GetObject(Trim(strfilename), "Excel.Sheet")

strsql = "select * from School.mdb"
'rsupload.Open strsql, conn, adOpenDynamicm, adLockOptimistic
rsupload.Open strsql, conn, adOpenStatic, adLockOptimistic, adCmdTable

intcount = 0
x = 1

Do While Not (objexcel.ActiveSheet.Range("A" & CStr(x)) = "")
If Not objexcel Is Nothing Then
intcount = incount + 1
x = intcount
If ((x = 1) And ((objexcel.ActiveSheet.Range("A" & CStr(1))) <> "SrNo")) Then
Screen.MousePointer = vbDefault
MsgBox "Not Appropriate file", vbCritical + vbOKOnly, "Upload Excel File Error"
rsupload.Close
' changeuploadstatus ("N")

Set rsupload = Nothing
Set objexcel = Nothing

Exit Function
End If
'---------------------------------------------------------------------------
If objexcel.ActiveSheet.Range("A" & CStr(x)) <> "SrNo" Then
strsrno = obsjexcel.ActiveSheet.Range("A" & CStr(x))
strfname = objexcel.ActiveSheet.Range("B" & CStr(x))
strlname = objexcel.ActiveSheet.Range("C" & CStr(x))

'Insert into Table1 (Srno,firstname,lastname) values('" & strsrno &'", '"&strfname&'", '"&strlname&'")
strsql = "Insert Into Table1 (SrNo, firstname, lastname)values('" & strsrno & "', '" & strfname & "','" & strlaname & "')"

conn.Execute strsql


End If
End If
x = x + 1
Loop
Else
UploadExcel = False
Screen.MousePointer = vbDefault
End If

If rsupload.State = adStateOpen Then rsupload.Close
If rssrno.State = adStateOpen Then rssrno.Close

Set rssrno = Nothing
Set rsupload = Nothing
Set objexcel = Nothing

Exit Function

Err:
Screen.MousePointer = vbDefault
MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "UploadexcelFile error..."

UploadExcel = False
Resume
rsupload.Close
rssrno.Close

Set rssrno = Nothing
Set rsupload = Nothing
Set objexcel = Nothing


End Function
Aug 6 '07 #3
lucky13
24
Can you explain little bit more. and what you had tryed till now?
Expand|Select|Wrap|Line Numbers
  1. Private Function UploadExcel() As Boolean
  2.  
  3.     On Error GoTo Err
  4.  
  5.     Dim rstemp As New ADODB.Recordset
  6.     Dim rsupload As New ADODB.Recordset
  7.     Dim rssrno As New ADODB.Recordset
  8.     Dim objexcel As Object
  9.     Dim strsql As String
  10.     Dim strfilename As String
  11.     Dim intcount As Integer, x As Long
  12.     Dim strfname As String, strlname As String, strsrno As String
  13.  
  14.     conn.Open
  15.     'cn.Open
  16.     rsupload.CursorLocation = adUseClient
  17.     rstemp.CursorLocation = adUseClient
  18.     rssrno.CursorLocation = adUseClient
  19.   '  UploadExcel = False
  20.  
  21.     'strfilename = frmInputBox.InputString("Select upload file", "Upload File...", "", , "xls")
  22.     'strfilename = InputBox("Select excel file for Upload", "Upload File...", "", "xls")
  23.     'strfilename = InputBox("Select upload file", "Upload File...", "", , "xls")        'PLEASE CHECK THE PARAMETER SEQUENCE
  24.  
  25.     strfilename = InputBox("Select Upload File", "Upload Files....", "")
  26.  
  27.  
  28.     MsgBox "File Uploading Started", vbOKOnly + vbInformation, "Uploading"
  29.  
  30.     If Trim(strfilename) <> "" Then
  31.     Screen.MousePointer = vbHourglass
  32.  
  33.     Set objexcel = GetObject(Trim(strfilename), "Excel.Sheet")
  34.  
  35.     strsql = "select * from Table1"
  36.     'rsupload.Open strsql, conn, adOpenDynamicm, adLockOptimistic
  37.     rsupload.Open strsql, conn, adOpenStatic, adLockOptimistic, adCmdTable
  38.  
  39.     intcount = 0
  40.     x = 1
  41.  
  42.     Do While Not (objexcel.ActiveSheet.Range("A" & CStr(x)) = "")
  43.         If Not objexcel Is Nothing Then
  44.             intcount = incount + 1
  45.             x = intcount
  46.             If ((x = 1) And ((objexcel.ActiveSheet.Range("A" & CStr(1))) <> "SrNo")) Then
  47.                 Screen.MousePointer = vbDefault
  48.                 MsgBox "Not Appropriate file", vbCritical + vbOKOnly, "Upload Excel File Error"
  49.                 rsupload.Close
  50. '                changeuploadstatus ("N")
  51.  
  52.                 Set rsupload = Nothing
  53.                 Set objexcel = Nothing
  54.  
  55.                 Exit Function
  56.             End If
  57.         '---------------------------------------------------------------------------
  58.             If objexcel.ActiveSheet.Range("A" & CStr(x)) <> "SrNo" Then
  59.                 strsrno = obsjexcel.ActiveSheet.Range("A" & CStr(x))
  60.                 strfname = objexcel.ActiveSheet.Range("B" & CStr(x))
  61.                 strlname = objexcel.ActiveSheet.Range("C" & CStr(x))
  62.  
  63.                 'Insert into Table1 (Srno,firstname,lastname) values('" & strsrno &'", '"&strfname&'", '"&strlname&'")
  64.                 strsql = "Insert Into Table1 (SrNo, firstname, lastname)values('" & strsrno & "', '" & strfname & "','" & strlaname & "')"
  65.                 conn.Execute strsql
  66.  
  67.             End If
  68.         End If
  69.         x = x + 1
  70.         Loop
  71.     Else
  72.         UploadExcel = False
  73.         Screen.MousePointer = vbDefault
  74.     End If
  75.  
  76.     If rsupload.State = adStateOpen Then rsupload.Close
  77.     If rssrno.State = adStateOpen Then rssrno.Close
  78.  
  79.     Set rssrno = Nothing
  80.     Set rsupload = Nothing
  81.     Set objexcel = Nothing
  82.  
  83. Exit Function
  84.  
  85. Err:
  86. Screen.MousePointer = vbDefault
  87. MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "UploadexcelFile error..."
  88.  
  89. UploadExcel = False
  90. Resume
  91. rsupload.Close
  92. rssrno.Close
  93.  
  94. Set rssrno = Nothing
  95. Set rsupload = Nothing
  96. Set objexcel = Nothing
  97.  
  98.  
  99. End Function
  100.  
My database name is school.mbd & the excel file name is Text1.xls. & I create one DSN name as school, Access database is attached to this.
Aug 6 '07 #4
hariharanmca
1,977 1GB
Expand|Select|Wrap|Line Numbers
  1. Private Function UploadExcel() As Boolean
  2.  
  3.     On Error GoTo Err
  4.  
  5.     Dim rstemp As New ADODB.Recordset
  6.     Dim rsupload As New ADODB.Recordset
  7.     Dim rssrno As New ADODB.Recordset
  8.     Dim objexcel As Object
  9.     Dim strsql As String
  10.     Dim strfilename As String
  11.     Dim intcount As Integer, x As Long
  12.     Dim strfname As String, strlname As String, strsrno As String
  13.  
  14.     conn.Open
  15.     'cn.Open
  16.     rsupload.CursorLocation = adUseClient
  17.     rstemp.CursorLocation = adUseClient
  18.     rssrno.CursorLocation = adUseClient
  19.   '  UploadExcel = False
  20.  
  21.     'strfilename = frmInputBox.InputString("Select upload file", "Upload File...", "", , "xls")
  22.     'strfilename = InputBox("Select excel file for Upload", "Upload File...", "", "xls")
  23.     'strfilename = InputBox("Select upload file", "Upload File...", "", , "xls")        'PLEASE CHECK THE PARAMETER SEQUENCE
  24.  
  25.     strfilename = InputBox("Select Upload File", "Upload Files....", "")
  26.  
  27.  
  28.     MsgBox "File Uploading Started", vbOKOnly + vbInformation, "Uploading"
  29.  
  30.     If Trim(strfilename) <> "" Then
  31.     Screen.MousePointer = vbHourglass
  32.  
  33.     Set objexcel = GetObject(Trim(strfilename), "Excel.Sheet")
  34.  
  35.     strsql = "select * from Table1"
  36.     'rsupload.Open strsql, conn, adOpenDynamicm, adLockOptimistic
  37.     rsupload.Open strsql, conn, adOpenStatic, adLockOptimistic, adCmdTable
  38.  
  39.     intcount = 0
  40.     x = 1
  41.  
  42.     Do While Not (objexcel.ActiveSheet.Range("A" & CStr(x)) = "")
  43.         If Not objexcel Is Nothing Then
  44.             intcount = incount + 1
  45.             x = intcount
  46.             If ((x = 1) And ((objexcel.ActiveSheet.Range("A" & CStr(1))) <> "SrNo")) Then
  47.                 Screen.MousePointer = vbDefault
  48.                 MsgBox "Not Appropriate file", vbCritical + vbOKOnly, "Upload Excel File Error"
  49.                 rsupload.Close
  50. '                changeuploadstatus ("N")
  51.  
  52.                 Set rsupload = Nothing
  53.                 Set objexcel = Nothing
  54.  
  55.                 Exit Function
  56.             End If
  57.         '---------------------------------------------------------------------------
  58.             If objexcel.ActiveSheet.Range("A" & CStr(x)) <> "SrNo" Then
  59.                 strsrno = obsjexcel.ActiveSheet.Range("A" & CStr(x))
  60.                 strfname = objexcel.ActiveSheet.Range("B" & CStr(x))
  61.                 strlname = objexcel.ActiveSheet.Range("C" & CStr(x))
  62.  
  63.                 'Insert into Table1 (Srno,firstname,lastname) values('" & strsrno &'", '"&strfname&'", '"&strlname&'")
  64.                 strsql = "Insert Into Table1 (SrNo, firstname, lastname)values('" & strsrno & "', '" & strfname & "','" & strlaname & "')"
  65.                 conn.Execute strsql
  66.  
  67.             End If
  68.         End If
  69.         x = x + 1
  70.         Loop
  71.     Else
  72.         UploadExcel = False
  73.         Screen.MousePointer = vbDefault
  74.     End If
  75.  
  76.     If rsupload.State = adStateOpen Then rsupload.Close
  77.     If rssrno.State = adStateOpen Then rssrno.Close
  78.  
  79.     Set rssrno = Nothing
  80.     Set rsupload = Nothing
  81.     Set objexcel = Nothing
  82.  
  83. Exit Function
  84.  
  85. Err:
  86. Screen.MousePointer = vbDefault
  87. MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "UploadexcelFile error..."
  88.  
  89. UploadExcel = False
  90. Resume
  91. rsupload.Close
  92. rssrno.Close
  93.  
  94. Set rssrno = Nothing
  95. Set rsupload = Nothing
  96. Set objexcel = Nothing
  97.  
  98.  
  99. End Function
  100.  
My database name is school.mbd & the excel file name is Text1.xls. & I create one DSN name as school, Access database is attached to this.
lucky13, just post only that method and where you are getting the problem and what are the solution you need. Then only we can analysis your code.
Do not dump a huge code. Post very few code and explain more.
Aug 6 '07 #5
lucky13
24
can anybody please help in how to import Excel data into Access through VB. i have written program. I am getting Error as Syntax error FROM Clause.....
Aug 11 '07 #6
Scott Price
1,384 Expert 1GB
can anybody please help in how to import Excel data into Access through VB. i have written program. I am getting Error as Syntax error FROM Clause.....
You have posted this in the Visual Basic forum, it should properly be posted in the Access forum, as the VBA that Access uses is different from 'regular' VisualBasic...

Perhaps one of the moderators can move it across for you.

Regards,
Scott
Aug 11 '07 #7
lucky13
24
thnks , my problem has been solved.
Aug 17 '07 #8
Please share what the correction what I'm having the same issue.
Aug 17 '07 #9
lucky13
24
Please share what the correction what I'm having the same issue.
sorry for replying late., u r problem has solved or not. if not then pls, let me know.

regards
lucky13
Sep 17 '07 #10
Hi Lucky,

Plz give me the solution. How u did it? As i m also having the same problem.

Thanx in advance.
Sep 17 '07 #11
lucky13
24
Hi Lucky,

Plz give me the solution. How u did it? As i m also having the same problem.

Thanx in advance.
please let me know where exactly u r getting problem....
Sep 17 '07 #12

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

Similar topics

2
by: Sreedhar Vankayala | last post by:
Hi, I joined a project where we need to import data from a excel file into sql server via the asp.net. After doing a long research found that #1. Upload Excel file to the server #2. Load or...
5
by: Seok Bee | last post by:
Dear Experts, I currently trying to use the FileUpload control from asp.net 2.0 to upload files. The uploading of the file I would like to store it in the Access Database. Unfortunately, I've no...
0
by: shaurya.rastogi | last post by:
I need to open an Excel file that has been stored in the Access Database using the insert Object functionality of MSAccess manually. What i am aware of is that i cant just read the field...
0
by: shaurya | last post by:
I need to open an Excel file that has been stored in the Access Database using the insert Object functionality of MSAccess manually. What i am aware of is that i cant just read the field...
2
by: solargovind | last post by:
Hi, Can anybody suggest me how to take data from an Excel file without import into Access as a Table..? Bcoz...I hve several file. if i import, it would take more time and increase the file...
6
by: rlntemp-gng | last post by:
I need to extract information from some Excel files but am stuck with part of it: As an example, I have the following Excel File that has 3 tabbed sheets: FileName: ...
2
by: danssy | last post by:
hi all frens i need to save the Excel file i upload "d:MYEXCEL.XSL" in WEB server i use html <input type=file > and submit button i also need to carry over my original excelfile name and...
2
by: BankGirl | last post by:
hi i am trying to open a excel spreadsheet automatically at the push of a button. i am using the below code that i obtained via another help message but i keep getting an error message saying...
2
by: Ehsan arman | last post by:
I was wondering how I could read excel file names in a particular folder using Access VBA. I need to compare the file names in that folder with what I have in a field of Access table.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.