Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type MisMatch Error?? 1

Status
Not open for further replies.

WB786

MIS
Mar 14, 2002
610
I am getting the type mismatch error on this line: Set rs = db.OpenRecordset(SQLstr, dbReadOnly)

I am using Access 2002 and Sql 2000 - the whole code is listed below. Thanks.

Private Sub GetRecord_Click()
If Not IsNull(Me.empid) Then

Const dbReadOnly = 4
Dim db As Database
Dim rs As Recordset
Dim SQLstr As String
Dim USERID As String

USERID = Forms!frmTermEmp_IN![empid]

SQLstr = "SELECT * From tblEmployees WHERE tblEmployees.Emp_Tracker= '" & USERID & "';"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLstr, dbReadOnly)

Do 'for every record in selection:
If rs(&quot;Emp_FirstName&quot;) <> &quot;&quot; Then Forms!frmTermEmp_IN![Emp_FirstName] = rs(&quot;Emp_FirstName&quot;)
If rs(&quot;Emp_LastName&quot;) <> &quot;&quot; Then Forms!frmTermEmp_IN![Emp_LastName] = rs(&quot;Emp_LastName&quot;)


rs.MoveNext
Loop Until rs.EOF

rs.Close
db.Close
Else
MsgBox &quot;Please Select An Employee First&quot;, vbCritical, &quot;Error&quot;
End If
End Sub
 
Try changing Dim rs As Recordset to Dim rs as DAO.Recordset



DBAMJA

It is said that God will give you no more than you can handle. I just wish God didn't have so much faith in me.
 
I think maybe your where clause is using single quotes which works fine in, say, VFP but not in DAO. You might try

&quot;SELECT * From tblEmployees WHERE tblEmployees.Emp_Tracker= &quot; & CHR(34) & USERID & CHR(34) & &quot;;&quot;



JHall
 
DBAMJA,

Thank you that worked!!!

 
One more question: I got this code from someone at my previous job and the way she had her database was to add entry to a tblterms (local table) but what I want to do is just pull up the record from tblEmployees and update the existing record on sql. Is that possible? Thanks.

:)Wb
 
It is really not as difficult as it may seem. Are the changes that you are making coming from a form or are they just global changes (ie: the same update for every employee)?

[flush]

DBAMJA

It is said that God will give you no more than you can handle. I just wish God didn't have so much faith in me.
 
It is not a global change. What I was trying to do was that a manager would pull up the employee by their login id then click on get record and the coding above would pull up the employee info then the manager could update their record and then close the form.

Thanks,

:)WB
 
What might be easier in the long run is using a form that has a combo box on it with the employee names and ids and when the manager picks an id the form is filled in from the combo box. That way the data is being updated as the manager makes changes.



DBAMJA

It is said that God will give you no more than you can handle. I just wish God didn't have so much faith in me.
 
That is how I was going to do it first but then the combo box becomes to wide as there are close to 15 fields that need to be pulled up for each given employee. Is there way then to make the combo box to show only the employee name and id and not the other 13 fields but I am still able to bound to those columns.

Thanks,
:)WB
 
When you drop the combo box on your form, be sure that you have Access set to run the combo box wizard. It will allow you to pick what fields you want in the combo box and it will also ask you if you want to look up the record associated with the value in the combo box. I use this all of the time and it works just great.



DBAMJA

It is said that God will give you no more than you can handle. I just wish God didn't have so much faith in me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top