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

Data Conversion Error

I have a field in a recordset which is a string. It can look like
this: 13-15-67-56

I need to break out this string into numbers to run in queries to open
recordsets.

But when I try to open the recordset I get the data conversion error
3421.

I have tried using the format function to convert the string and it
doesn't work. But if I get the strSQL statement from the Immediate
window and paste it into a query it works fine with no errors.

Here's some of the code:

With rstSearchTable
If .RecordCount > 0 Then
.MoveFirst

strSubBrands = ""
srchPos = InStr(!SubBrandSK, "-")
'See if there is more than one subBrand
If srchPos > 0 Then
strSubBrands = Left(!SubBrandSK, srchPos - 1)

'Dim newsubbrand As Long
'newsubbrand = Format(strSubBrands, "General Number")
'newsubbrand = Format(strSubBrands, "standard")

Do Until .EOF
'Get subBrands
' strSQL = "SELECT * FROM Brand WHERE SK = " & newsubbrand
& ";"
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands
& ";"
'strSQL = "SELECT * FROM Brand WHERE SK = " &
Format(strSubBrands, "Standard") & ";"

Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)

Loop
.MoveNext
Else
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands &
";"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)
End If
End If
End With

I left some of the commented out code in there to show what I've been
trying.

Any help would be greatly appreciated.

Dec 19 '05 #1
6 2268

"Ecohouse" <vi*******@netzero.com> schreef in bericht news:11**********************@g49g2000cwa.googlegr oups.com...
I have a field in a recordset which is a string. It can look like
this: 13-15-67-56

I need to break out this string into numbers to run in queries to open
recordsets.

But when I try to open the recordset I get the data conversion error
3421.

I have tried using the format function to convert the string and it
doesn't work. But if I get the strSQL statement from the Immediate
window and paste it into a query it works fine with no errors.

Here's some of the code:

With rstSearchTable
If .RecordCount > 0 Then
.MoveFirst

strSubBrands = ""
srchPos = InStr(!SubBrandSK, "-")
'See if there is more than one subBrand
If srchPos > 0 Then
strSubBrands = Left(!SubBrandSK, srchPos - 1)

'Dim newsubbrand As Long
'newsubbrand = Format(strSubBrands, "General Number")
'newsubbrand = Format(strSubBrands, "standard")

Do Until .EOF
'Get subBrands
' strSQL = "SELECT * FROM Brand WHERE SK = " & newsubbrand
& ";"
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands
& ";"
'strSQL = "SELECT * FROM Brand WHERE SK = " &
Format(strSubBrands, "Standard") & ";"

Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)

Loop
.MoveNext
Else
strSQL = "SELECT * FROM Brand WHERE SK = " & strSubBrands &
";"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)
End If
End If
End With

I left some of the commented out code in there to show what I've been
trying.

Any help would be greatly appreciated.


strSubBrands is initialised as a string "" but you want to use a numeric value?
You could try: strSQL = "SELECT * FROM Brand WHERE SK = " & Clng(strSubBrands)

When formatting a string the string still remains a string...
With Clng() or CInt() you are converting...
Btw You don't need the ";" when building a SQL-string

HTH
Arno R
Dec 19 '05 #2
Thanks for the help.

I've already tried that. I even tried the following:
strSQL = "SELECT * FROM Brand WHERE SK = 13;"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)

This still returned the same error. So it's not that field. When I
try to look at the Brand table while debugging it says 'You can't open
the table 'Brand' for modification." It says the table is bound to a
form, etc.

Could this be causing the problem?

Dec 19 '05 #3

"Ecohouse" <vi*******@netzero.com> schreef in bericht news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks for the help.

I've already tried that. I even tried the following:
strSQL = "SELECT * FROM Brand WHERE SK = 13;"
Set rstSubBrands = .OpenRecordset(strSQL, dbOpenDynaset)

This still returned the same error. So it's not that field. When I
try to look at the Brand table while debugging it says 'You can't open
the table 'Brand' for modification." It says the table is bound to a
form, etc.

Could this be causing the problem?


No. Access just says that you can't modify the table.
You are still able to look at the table when that message comes up.

But I don't understand your problem anymore ...
You said 'it' worked when you pasted the SQL from the Immediate window...
What exactly did that SQL look like?
Did you try to set a breakpoint to debug the code?

Also: I see that besides your problem the Loop is endless...
I guess you need .MoveNext BEFORE the Loop.

HTH
Arno R

Arno R

Dec 19 '05 #4
Maybe:

********
Your code:

With rstSearchTable
<snips>
..OpenRecordset(strSQL, dbOpenDynaset)

*****************
DAO Object Documentation:

Function OpenRecordset([Type], [Options]) As Recordset
Member of DAO.Recordset

****************
Maybe a DAO recordset can open another DAO recordset with an SQL
string, I've never tried. But this would be outside the documentation.
The documentation (not the help documentation, the help file is mostly
just guesses) says the first argument is an optional Type which
probably must be numeric.

Dec 19 '05 #5
Thanks for all the help. I was able to solve the problem. I
originally set the currentdb as a global field. And even though I was
using it in a with statement, the code wasn't seeing it. So once I
added that to where I was opening the recordset it worked.

The error was misleading because it didn't deal with any data
conversion. If the error had said that there was a db connection
problem I could have quickly solved this problem.

Dec 19 '05 #6
You're one hundred per cent right. Only a genius could have recognized
what was wrong.

Dec 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
4
by: wb | last post by:
Newbie at .net having trouble with data conversion. I am using the random constructor and trying to pass in seed value of time as instructed by help. rvalue = new random(int) dim x as long...
4
by: alacrite | last post by:
I have a class that I want to turn its contents into csv file. I want to be able to set the value of the delimiter, the name of the file it gets saved to, the path of that file, and maybe a few...
3
by: fazulu deen | last post by:
Hi all, For the following code : file_ptr = fopen("pass_fail.txt", "a"); // error line 393 fdisplay(file_ptr, "Test Passed"); fclose(file_ptr);
1
by: Javilen | last post by:
Hello, edit: added some more info I am trying to set up a job to run a SSIS package in SQL 2005, the SQL 2005 is installed on a Windows server 2003 machine. start Edit I have the...
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.