Results 1 to 22 of 22

Thread: how to get the data on a text box?

Threaded View

  1. #13
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to get the data on a text box?

    Try testing for no records returned
    Code:
    Private Sub Form_Load()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\user\Desktop\NEW DB\FAITH.mdb;Persist Security Info=False"
    cn.Open
    Set rs = New ADODB.Recordset
    With rs
        .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open (" select * from faith where employee_id= ' " & Form2.Text1.Text & " '")
    End With
    If Not (rs.BOF And rs.EOF) Then
        DataGrid1.Refresh
        DataGrid1.DataSource = rs
    Else
        MsgBox "Query Returned No Records searching for Employee-ID:" & vbNewLine & Form2.Text1.Text
    End If
    End Sub
    EDIT: I see you have leading and trailing spaces in the Query,(and also in the Command4_Click Event code) vis:
    Code:
    ..... where employee_id= ' " & Form2.Text1.Text & " '"
    I suspect you mean:
    Code:
    ..... where employee_id= '" & Form2.Text1.Text & "'"
    or even
    Code:
    ..... where employee_id= '" & Trim$(Form2.Text1.Text) & "'"
    which will remove any leading or trailing spaces from the TextBox contents.
    Last edited by Doogle; May 20th, 2013 at 02:37 AM.

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