|
-
Apr 23rd, 2010, 11:10 PM
#1
Thread Starter
Lively Member
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:
Private Sub RetErive_Click()
Dim e As String
Dim sp As String
e = InputBox("Please Enter the Bill No", "Retrive")
Set ln = New ADODB.Connection
Set ls = New ADODB.Recordset
ln.ConnectionString = "Provider=microsoft.jet.oledb.4.0;" & "Data source =" & App.Path & "\Bills_Service.mdb"
ln.Open
sp = "Select * FROM BILLS WHERE Bill_No = " & e & ""
With ls
[COLOR="Red"].Open sp, ln, adOpenKeyset, adLockPessimistic, adCmdText[/COLOR]
End With
RID.Text = ls.Fields("RID").Value
Dob.Value = ls.Fields("Date of Bill").Value
Vend.Text = ls.Fields("Name of Vendor").Value
BillNo.Text = ls.Fields("Bill_No").Value
BillAmt.Text = ls.Fields("Bill Amount").Value
Stat.Text = ls.Fields("Del To").Value
Statdt.Value = ls.Fields("Del On").Value
Remark.Text = ls.Fields("Remarks").Value
CMC.Text = ls.Fields("CMC Ref No").Value
CheqNo.Text = ls.Fields("Cheque No").Value
Cheqdt.Value = ls.Fields("Cheque Date").Value
ls.Close
ln.Close
End Sub
Can anybody tell me what is wrong with code
Thanks
-
Apr 23rd, 2010, 11:30 PM
#2
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
-
Apr 24th, 2010, 12:04 AM
#3
Thread Starter
Lively Member
Re: Syntax Error
Thank you for the response
Infact i had did that Initially, which gave me the same problem
-
Apr 24th, 2010, 12:15 AM
#4
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,...
-
Apr 24th, 2010, 12:33 AM
#5
Thread Starter
Lively Member
Re: Syntax Error
Thank you, It was the spaces in the field names in access that created problem.
-
Apr 24th, 2010, 11:14 PM
#6
Re: Syntax Error
It's better not to have spaces in the names but you can do this:
sp = "Select * FROM BILLS WHERE [Bill No] = '" & e & "'"
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
|