Private Sub cmdusername_Click()
Set adorsRAM = New ADODB.Recordset
sSQL = "Select User from Master where CPU_No='" & txtcpuno.Text & "'"
MsgBox (sSQL)
With adorsRAM
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open sSQL
End With
If Not adorsRAM.EOF Then
'txtusername.Text = adorsRAM
Else
MsgBox "No Records Found!"
End If
End Sub

This is showing an error of type mismatch please check and help me out in finding the problem
thanks in advance

Edited 3 Years Ago by mike_2000_17: Fixed formatting

you can't assign an entire recordset to a textbox. You need to fetch one field of a record and display the same in the textbox.

You forgot to indicate the field that you want to display in textox:

If Not adorsRAM.EOF Then
  txtusername.Text = adorsRAM("NAMEOFYOURFIELD")
Else
  MsgBox "No Records Found!"
End If

or

If Not adorsRAM.EOF Then
  txtusername.Text = adorsRAM(1)
Else
  MsgBox "No Records Found!"
End If

where 1 is a zero-based index that assigns to a single field in your dataset.

Note that if you want to display ALL FIELDS data in the same text box, you'll loop through recordset or use GetString method.

Success!
Sidnei

start quote

Private Sub cmdusername_Click()
Set adorsRAM = New ADODB.Recordset
sSQL = "Select User from Master where CPU_No='" & txtcpuno.Text & "'"
MsgBox (sSQL)
With adorsRAM
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open sSQL
End With
If Not adorsRAM.EOF Then
'txtusername.Text = adorsRAM
Else
MsgBox "No Records Found!"
End If
End Sub

This is showing an error of type mismatch please check and help me out in finding the problem
thanks in advance

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.