Results 1 to 6 of 6

Thread: Syntax Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    Syntax Error

    Hello Everyone

    I am having a problem with the below mentioned code. It says Datatype mismatch. The bill no is a text field and not a numeric.

    Code Code:
    1. Private Sub RetErive_Click()
    2. Dim e As String
    3. Dim sp As String
    4.  
    5. e = InputBox("Please Enter the Bill No", "Retrive")
    6.  
    7. Set ln = New ADODB.Connection
    8. Set ls = New ADODB.Recordset
    9. ln.ConnectionString = "Provider=microsoft.jet.oledb.4.0;" & "Data source =" & App.Path & "\Bills_Service.mdb"
    10. ln.Open
    11. sp = "Select * FROM BILLS WHERE Bill_No = " & e & ""
    12.  
    13. With ls
    14. [COLOR="Red"].Open sp, ln, adOpenKeyset, adLockPessimistic, adCmdText[/COLOR]
    15. End With
    16.  
    17. RID.Text = ls.Fields("RID").Value
    18. Dob.Value = ls.Fields("Date of Bill").Value
    19. Vend.Text = ls.Fields("Name of Vendor").Value
    20. BillNo.Text = ls.Fields("Bill_No").Value
    21. BillAmt.Text = ls.Fields("Bill Amount").Value
    22. Stat.Text = ls.Fields("Del To").Value
    23. Statdt.Value = ls.Fields("Del On").Value
    24. Remark.Text = ls.Fields("Remarks").Value
    25. CMC.Text = ls.Fields("CMC Ref No").Value
    26. CheqNo.Text = ls.Fields("Cheque No").Value
    27. Cheqdt.Value = ls.Fields("Cheque Date").Value
    28.  
    29. ls.Close
    30. ln.Close
    31.  
    32. End Sub

    Can anybody tell me what is wrong with code

    Thanks

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Syntax Error

    since your field is text, then it needs to be in tick marks, to denote it as text:
    sp = "Select * FROM BILLS WHERE Bill_No = '" & e & "'"

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    Re: Syntax Error

    Thank you for the response

    Infact i had did that Initially, which gave me the same problem

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Syntax Error

    Some of the fields in that BILLS table contains <spaces> in field names. That will probably gives you some problems. Better try to create it as oneword or join it with underscore sign.

    Example:

    Date of Bill --> Date_of_Bill
    Name of Vendor --> Name_of_Vendor
    ...etc..

    Also, when text fields are used, you have to enclose them in single quotes ( ' ). techgnome already mentioned that.

    Eg:

    sp = "Select * FROM BILLS WHERE Bill_No = '" & e & "'"

    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    72

    Re: Syntax Error

    Thank you, It was the spaces in the field names in access that created problem.

  6. #6

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