Results 1 to 4 of 4

Thread: vb6 error

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    13

    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:
    1. 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.

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2014
    Posts
    13

    Re: vb6 error

    Quote Originally Posted by georgekar View Post
    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?

  4. #4
    gibra
    Guest

    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
  •  



Click Here to Expand Forum to Full Width