-
Oct 14th, 2005, 12:55 PM
#1
Thread Starter
Member
Query must have at least one destination field
Hi,
I receive the folowing error message in VB
"Query must have at least one destination field"
When I try to open a recordset
The code is:
Public Function AppendElement(elemento As ELEMENT) As ERROR_CODE
On Error GoTo err
'Creates a recordset to write the data to the file DB
Dim RsData As New ADODB.Recordset
With RsData
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
End With
If DBPresent = False Then
AppendElement = DB_NOT_OPEN
Exit Function
End If
Debug.Print connFileDB
Select Case FileType
Case ftXLS
Call RsData.Open("SELECT * FROM [A:Q]", connFileDB)
Case ftCSV
Call RsData.Open("SELECT * FROM " & FileName, connFileDB)
Case ftTOTA
Call RsData.Open("SELECT * FROM " & FileName, connFileDB)
End Select
ConnFileDB as the following
Provider=MSDASQL.1;Extended Properties="DBQ=C:\Documents and Settings\LMCamoes\Desktop\Totta\;DefaultDir=C:\Documents and Settings\LMCamoes\Desktop\Totta;Driver={Microsoft Text Driver (*.txt; *.csv)};DriverId=27;Extensions=asc,csv,tab,txt;MaxBufferSize=2048;PageTimeout=5;"
Can you help me?
Thank you
-
Oct 14th, 2005, 01:39 PM
#2
Lively Member
Re: Query must have at least one destination field
Where is the variable 'FileName' being set?
Create a variable for your SQL statement and build it before you open RsData so you can check it before it tries to open.
When you open you database do RsData.Open [your SQL], connfiledb, adOpenStatic, adLockPessimistic, adCmdText
-
Oct 17th, 2005, 03:50 AM
#3
Thread Starter
Member
Re: Query must have at least one destination field
I changes slightly the code and I have the same error.
What I have now is:
Public Function AppendElement(elemento As ELEMENT) As ERROR_CODE
On Error GoTo err
'Creates a recordset to write the data to the file DB
Dim RsData As New ADODB.Recordset
With RsData
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
End With
If DBPresent = False Then
AppendElement = DB_NOT_OPEN
Exit Function
End If
Debug.Print connFileDB
Dim sqlstr As String
sqlstr = "SELECT * FROM " & FileName
Debug.Print sqlstr
Select Case FileType
Case ftXLS
Call RsData.Open("SELECT * FROM [A:Q]", connFileDB)
Case ftCSV
Call RsData.Open("SELECT * FROM " & FileName, connFileDB)
Case ftTOTA
RsData.Open sqlstr, connFileDB, adOpenStatic, adLockPessimistic, adCmdText
' Call RsData.Open("SELECT * FROM " & FileName, connFileDB)
End Select
RsData.AddNew
...
Where sqlstr is:
"SELECT * FROM teste.CSV"
and connFileDB is :
Provider=MSDASQL.1;Extended Properties="DBQ=C:\Documents and Settings\LMCamoes\Desktop\Totta\;DefaultDir=C:\Documents and Settings\LMCamoes\Desktop\Totta;Driver={Microsoft Text Driver (*.txt; *.csv)};DriverId=27;Extensions=asc,csv,tab,txt;MaxBufferSize=2048;PageTimeout=5;"
but when it tries to open the recordset gives the error...
Please help me
-
Oct 17th, 2005, 04:18 AM
#4
Re: Query must have at least one destination field
On what specific line does the error occurs?
-
Oct 19th, 2005, 04:03 AM
#5
Thread Starter
Member
Re: Query must have at least one destination field
the error append when I try to open the recodset.
-
Oct 19th, 2005, 10:26 AM
#6
Re: Query must have at least one destination field
This error will occur if the file is empty. The header row (first line) in the file is assumed to be the field names.
I think there is an extended property you can use to indicate there is no header row in the file but I can't remember the syntax. I think its just HDR=NO.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|