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

Error 3421: "Data Type Conversion Error.

Hi Guys

Season greetings to everyone.

Does anyone have an idea to this error message.

Thanks
gilsygirl
Dec 17 '07 #1
10 4946
debasisdas
8,127 Expert 4TB
that simply means the target variable and the content does not match.
Dec 17 '07 #2
that simply means the target variable and the content does not match.
Hi thanks for the reply. how do i treat a text variable define as string. cos that is all i have done. but the error keeps coming from my sql statement.
Is there any other suggestion u have.

thanks
Dec 24 '07 #3
debasisdas
8,127 Expert 4TB
Hi thanks for the reply. how do i treat a text variable define as string. cos that is all i have done. but the error keeps coming from my sql statement.
Is there any other suggestion u have.

thanks
Kindly post what exactly youare trying to do and also the SQL statment that you are trying to execute.
Dec 24 '07 #4
Killer42
8,435 Expert 8TB
Ignore me. I'm just registering an interest in this thread so I can tell when new messages are posted.
Dec 24 '07 #5
Kindly post what exactly youare trying to do and also the SQL statment that you are trying to execute.
Thanks for the reply

I am trying to extra a record from a database using a combination of 3 of the fields in the database as a key. So i am querying them in an Sqlstmt variable use as the recordset. the fields in the database are define as text and in the vb form the variable agruments are define as string.

So when i enter the variables on the form a second form should load displaying a record base on the variables passed provided it is in the database.

this my code

Expand|Select|Wrap|Line Numbers
  1. Public Function initdb()
  2. On Error GoTo error
  3. Set ws = DBEngine.Workspaces(0)
  4. Set db = ws.OpenDatabase("c:\resultchecker.mdb")
  5. Set rs = db.OpenRecordset("candres", dbOpenTable, dbReadOnly)
  6. Set rs1 = db.OpenRecordset("subject", dbOpenTable, dbReadOnly)
  7.  
  8. Exit Function
  9. End Function
  10.  
  11. Sub cmdCheck_click()
  12.  
  13. Dim Exam_Sr As String
  14. Dim Exam_Yr As String
  15. Dim Cand_No As String
  16. Dim CentNo As String
  17.  
  18. If rs.RecordCount = 0 Then Exit Sub
  19.    rs.MoveFirst
  20. For i = 1 To rs.RecordCount ' Read all the records from database
  21.  
  22. sqlStmt = "select * From candres where ExamSeries='" & Exam_Sr & "'and ExamYear='" & Exam_Yr & "'and CentNo='" & Cand_No & "'"
  23.     rs.OpenRecordset sqlStmt, db
  24.  
  25. If Not (rs.EOF) Then
  26.        frmCandResult.Show vbModal, Me
  27.     Else
  28.         MsgBox "sorry not a perfect match"
  29.     End If
  30.  
  31. CentNo = rs("CentNo")
  32. Cand_No = rs("IndexNo")
  33. Sex = rs("Sex")   
  34.  
  35.  frmListing.Cent_No.Caption = rs("CentNo")
  36.    frmListing.Cand_No.Caption = rs("IndexNo")
  37.    frmListing.Cnd_Name.Caption = rs("CandName")
  38.  
  39.     frmListing.Show vbModal, Me
  40.        rs.MoveNext
  41.        Next i
  42. End Sub
Dec 27 '07 #6
debasisdas
8,127 Expert 4TB
1. Which line of code is creating the error ?
2. Why using a function with out any out type and nothing to return ?
3. Why opening the same recordset twice from two different sources ?
4. You have never called the function in the click event.
5. Try to use ADO code , that is much more flexible.
Dec 27 '07 #7
Killer42
8,435 Expert 8TB
My guess is that the CentNo field is numeric. If you have a close look at line 22 of the code, you'll see that it is being compared to variable Cand_No, delimited by quotes. This may be the source of the problem.
Dec 27 '07 #8
1. Which line of code is creating the error ?
2. Why using a function with out any out type and nothing to return ?
3. Why opening the same recordset twice from two different sources ?
4. You have never called the function in the click event.
5. Try to use ADO code , that is much more flexible.
Thanks for the reply. I have been able to solve the query. I was passing the values to a different form then the required form. The new query is in the SQL statement. It is only picking the first record in the database.

Now I want to know which function you are referring to and where I am opening the recordset twice.
Thanks for the help, really appreciated.
gilsygirl newbie
Jan 2 '08 #9
My guess is that the CentNo field is numeric. If you have a close look at line 22 of the code, you'll see that it is being compared to variable Cand_No, delimited by quotes. This may be the source of the problem.
Thanks for the reply. I have been able to solve the query. My latest problem is the SQL statement. It is only picking the first record from the database.

This is the code:
Expand|Select|Wrap|Line Numbers
  1. If rs.RecordCount = 0 Then Exit Sub
  2. rs.MoveFirst
  3. For i = 1 To rs.RecordCount ' Read all the records from database
  4.  
  5.   sqlStmt = "select * From candres where ExamSeries='" & Exam_Sr & "'and ExamYear='" & Exam_Yr & "'and CentNo='" & Cand_No & "'"
  6.   rs.OpenRecordset , sqlStmt
  7.  
  8.   If Not (rs.EOF) Then
  9.     Call dispres
  10.     ' frmListing.Show vbModal, Me
  11.   Else
  12.      MsgBox "sorry not a perfect match"
  13.   End If
  14.  
What is wrong with this code?

Thanks for help it's really appreciated.
gilsygirl newbie
Jan 2 '08 #10
Killer42
8,435 Expert 8TB
... What is wrong with this code?
Not sure where to start. :)

But one thing to consider is that RecordCount may not be populated until the records are accessed. When you first open the recordset, I think it just holds 0 (if no records) or 1 (if any records). So you might see some improvement if you insert rs.MoveLast before line 2. Hm... or since you're immediately replacing rs anyway, maybe just change line 2 from MoveFirst to MoveLast.



I have a question. Is the recordset opened in line 5 supposed to contain the same records that were already in rs when we entered this part of the code? If so, there's no need to open anything, which I think is what Veena was getting at. You have the records there, just go ahead and use them.
Jan 3 '08 #11

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

Similar topics

3
by: 21novembre | last post by:
Hi all, I made a question several days before to describe my strange trouble of mysqldump. But I still can't figour it out. Well, I just want to ask another question whether I could just backup...
1
by: Esben Rune Hansen | last post by:
Hi I am working on a PHP-script and need javascript to set the value of a hidden field in a form. This field happens to be an entry in an array data according to my example. How can I do this? ...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
0
by: John Smith | last post by:
Hi I am getting the above error when I try to run the union query shown below select all as , as , as , as , ,, ,, , , as , as , as , as , as from
4
by: Saso Zagoranski | last post by:
Hi! I have created an SqlCommand object and I have set some parameters to it... One of the parameters is of the DateTime type; here is the code: sqlCommand.Parameters.Value =...
11
by: sofeng | last post by:
I'm not sure if "data hiding" is the correct term, but I'm trying to emulate this object-oriented technique. I know C++ probably provides much more than my example, but I'd just like some feedback...
8
by: mdh | last post by:
May I ask this. Given the declaration: int myf( int, int); and a function pointer: (*fp)=int myf(int, int); where I am initializing fp to point at myf....or trying to..
3
by: eros | last post by:
ALTER TABLE public.postcodes ALTER COLUMN machi TYPE varchar(100); Error: ERROR: syntax error at or near "TYPE"; Error while executing the query (State:42601, Native Code: 7) I am using...
18
by: Stephan Beal | last post by:
Hi, all! Before i ask my question, i want to clarify that my question is not about the code i will show, but about what the C Standard says should happen. A week or so ago it occurred to me...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.