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

Recommended Answers

All 3 Replies

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

thanx a lot to all of you
I was able to solve it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.