Results 1 to 22 of 22

Thread: ADO with SQL Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    ADO with SQL Problem

    i have got this code from here

    http://www.vbforums.com/showthread.php?t=416225

    i get this error for some reason:

    Data type mismatch in criteria expression

    this is the code:
    Attached Images Attached Images  
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ADO with SQL Problem

    What type of field is Serial?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    text although it has a number in it
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ADO with SQL Problem

    Then you need single quotes around the entry.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    if single qoutes are '' then now the value = 0 and i still get the error

    the full code i am using is :
    Code:
    Private Sub cmdSearch_Click()
    Dim strSQL As String
    'build the SQL statement based on what the user typed in txtSearch
    strSQL = "SELECT * FROM tblActivation"
    If txtSearch.Text <> "" Then
    strSQL = strSQL & " WHERE Serial = " & Val(txtSearch.Text)
    End If
    'close the recordset (required before reloading it)
    rs.Close
    'load the new data
    rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
    'show the data
    fillfields
    End Sub
    by the way i put '31031101059811167' in the textbox
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: ADO with SQL Problem

    If the Serial field in the DB is text is doesnt mater if it is only holding numbers it is still text and the values must be surrounded by single qoutes like this:

    Code:
    Dim strSQL As String
    'build the SQL statement based on what the user typed in txtSearch
    strSQL = "SELECT * FROM tblActivation"
    If txtSearch.Text <> "" Then
    strSQL = strSQL & " WHERE Serial = '" & Trim(Replace(txtSearch.Text,"'","'')) & "'"
    End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    i get a syntax error on this line:
    Code:
    strSQL = strSQL & " WHERE Serial = '" & Trim(Replace(txtSearch.Text,"'","'')) & "'"
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: ADO with SQL Problem

    I'm missing a double qoute after the two single qoutes before the closing paren for the Replace function.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    thanks that works now one more thing.

    When i do a search for something that isnt in the database i get a msgbox

    Either you are at the first record or at the last.

    is there a way that i can get rid of this message and make it set a variable as false.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: ADO with SQL Problem

    Try this:

    Code:
    if rs.State = adStateOpen Then rs.Close
    'load the new data
    rs.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
    If Not rs.BOF and Not rs.EOF Then
     'show the data
     fillfields
    Else
     MsgBox "No Records Found that match the search crieteria."vbOKOnly + vbInformation,"No Data Found"
    End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    i have moved the db to the web now i get invalid file nam

    "Data Source= http://ripway.com/act/activate.mdb" 'this is the connection string explained in the notes section.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  12. #12
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: ADO with SQL Problem

    ok im working with chris on this and i figured it out you use the ftp e.g.
    "Data Source= ftp.ripway.com/act/activate.mdb"
    but it also includes my desktop as part of the address how do i sort that out?
    the error looks like this...

    Thanks in advance
    Danny
    Attached Images Attached Images  

    If at first you dont succeed, destroy all evidence that you tried in the first place.

  13. #13
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    Re: ADO with SQL Problem

    VB might not like the # in the db path name.

    I also received that error when my select statement was incorrect trying connect to a FoxPro db.

  14. #14
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: ADO with SQL Problem

    I didn't tell it to use any part of my computer as you can see in the image (its the bit just above the error box) nor did i tell it to add a #, can anyone figure how to make it ignore my computer and only use the server please?

    thanks in advance

    If at first you dont succeed, destroy all evidence that you tried in the first place.

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ADO with SQL Problem

    Access does not support being used on the web, tho there is a (unreliable) way to do that, as shown in our Database FAQs.

    Note that this cannot use FTP, as that is File Transfer Protocol. Oh, and the reason for the desktop path being added there is that you did not specify a protocol (FTP), so the default (file) was assumed, and as it was not a full file path, it was appended to the 'current' directory.

  16. #16
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: ADO with SQL Problem

    thanks ill look in the database FAQS

    If at first you dont succeed, destroy all evidence that you tried in the first place.

  17. #17
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: ADO with SQL Problem

    i got it connecting now using a username and password but it cant open the file due to 'The workgroup information file is missing or opened exclusively by another user'
    btw chris has uploaded the workgroup information file

    If at first you dont succeed, destroy all evidence that you tried in the first place.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: ADO with SQL Problem

    Dannyg is working with me on this, we have now got it to connect to the db but by the looks of it it cant open the record set.

    This code is highlighted:
    Code:
    rs.Open "tblActivation", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    This is the Error:
    Attached Images Attached Images  
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  19. #19
    Lively Member
    Join Date
    Oct 2006
    Posts
    78

    Re: ADO with SQL Problem

    Can anyone help?

    If at first you dont succeed, destroy all evidence that you tried in the first place.

  20. #20
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: ADO with SQL Problem

    I'm afraid I have never used Access on the web (I have always used 'real' database systems like SQL Server instead), and have never seen that error before either.. I can only assume that it means that the specified table cannot be found in the database.

  21. #21
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: ADO with SQL Problem

    Try using
    Code:
    rs.open "tablename" ,cn,adOpenDynamic,adLockOptimistic
    If an answer to your question has been helpful, then please, Rate it!

  22. #22
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: ADO with SQL Problem

    It looks more like the error is telling you that IIS can't connect properly to Access.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width