-
Sep 15th, 2014, 01:35 AM
#1
Thread Starter
New Member
vb6 error
Hyy all
following is my code, the highlighted code is generating error as Type Mismatch. I am using sql database. for the Client_Name Cloumn I have used Varchar as Datatype.
Code:
Private Sub btn_RegClient_Click()
RS.AddNew
RS!REG_NO = TXT_REGNO
RS!REG_DATE = DT_REG
RS!CLIENT_NAME = txt_Client
RS!CLIENT_CATEGORY = DC_CATEGORY
RS!CONTACT_PERSON = txt_CPerson
RS!MAILING_ADDRESS = txt_Email
RS!MOBILE_NO = txt_cell
RS!PHONE_OFF = txt_Phone
RS!FAX_NO = txt_fax
RS!APPLICATION_NAME = txt_APPName
RS!APPLICATION_COST = Val(txt_AppCost)
RS!CONTRACT_PERIOD = txt_Cperiod
RS!area_name = DC_AREA
RS!city = DC_CITY
RS!country = DC_COUNTRY
If txt_Client = "" Then
MsgBox ("PLEASE PROVIDE CLIENT CREDENTIALS.")
RS.CancelUpdate
End If
Type Mismatch Error Generated here Code:
If "SELECT * FROM CLIENT WHERE CLIENT_NAME = ('" & txt_Client.Text & "')" Then
MsgBox ("RECORD ALREADY EXISTS")
RS.CancelUpdate
Else
RS.Update
End If
DATA_LOCK
DATA_CLEAR
Set DataGrid1.DataSource = RS
DataGrid1.Refresh
End Sub
any help is appreciated.
-
Sep 15th, 2014, 03:32 AM
#2
Re: vb6 error
this is fault
If "SELECT * FROM CLIENT WHERE CLIENT_NAME = ('" & txt_Client.Text & "')" Then
because is like this
if a$ then
You have to place a numeric expression
-
Sep 15th, 2014, 04:05 AM
#3
Thread Starter
New Member
Re: vb6 error
Originally Posted by georgekar
this is fault
If "SELECT * FROM CLIENT WHERE CLIENT_NAME = ('" & txt_Client.Text & "')" Then
because is like this
if a$ then
You have to place a numeric expression
But my DB Field is not numeric. now what should be done?
-
Sep 15th, 2014, 09:34 AM
#4
Re: vb6 error
Hi, yuor code:
Code:
If "SELECT * FROM CLIENT WHERE CLIENT_NAME = ('" & txt_Client.Text & "')" Then
is wrong because SELECT statement is used to open a recordset, or to execute a query i.e.
Code:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
sql = "SELECT * FROM CLIENT WHERE CLIENT_NAME = '" & txt_Client.Text & "'"
rs.Open sql, CN, adOpenForwardOnly, adLockReadOnly, adCmdText
If rs.Eof Then
MsgBox "Not Found"
End If
or
Code:
Set rs = CN.Execute(sql)
Also, may be that the CLIENT_NAME contains quotes, like: O'Reilly
Then you should use Replace() function to double quotes and avoid error :
Code:
Dim sClientName As String
sClientName = Replace(txt_Client.Text , "'", "''")
sql = "SELECT * FROM CLIENT WHERE CLIENT_NAME = '" & sClientName & "'"
rs.Open sql, CN, adOpenForwardOnly, adLockReadOnly, adCmdText
If rs.Eof Then
MsgBox "Not Found"
End If
But the best way of all is to use Command and Parameters. See link on my sign.
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
|