Runtime Error '13': Type Mismatch

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
636
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm not sure if this should be posted in the MS Access forum or Excel. I'm using the Excel userform on the front end and trying to retrieve the data on the back end.

I would like to create an autopopulated userform. If the user types in an employee ID, then the first & last name as well as that person's email address is automatically filled in on the form based on the data entered in MS Access. This is what I have so far.

USERFORM CONTROLS
5 Textboxes
1. txtEmpNum 'Employee ID
2. txtFN 'First Name
3. txtLN 'Last Name
4. txtEmail

VBA Code:
Private Sub txtEmpNum_Change()
    FindRecordInAccess
End Sub

VBA Code:
Sub FindRecordInAccess()

'Path
    Dim strPath As String
   
    'Provider
    Dim strProv As String
   
    'Connection String
    Dim strConn As String
   
    'Connection
    Dim Conn As New Connection
   
    'RecordSet
    Dim reqry As New Recordset
   
    'SQL Query
    Dim strQry As String
   
    strPath = "C:\Users\UO83254\OneDrive\Documents\Personnel.accdb"
    strProv = "Microsoft.ACE.OLEDB.12.0;"
    strConn = "Provider=" & strProv & "Data Source=" & strPath
   
    'Connection Open
    Conn.Open strConn
   
   
If Len(frmPersonnelEntry.txtEmpNum.Text) > 7 Then
        Dim defaultSql As String
        Dim strSQL As String
        
        defaultSql = "SELECT * FROM Personnel"
        
        strSQL = defaultSql & " WHERE " & [Employee #] & " LIKE '*" & frmPersonnelEntry.txtEmpNum.Text & "*'"[B] ERROR OCCURS HERE[/B]
       
        MsgBox "Record Found: "
        Debug.Print strQry
    Else
        MsgBox "Record NOT Found"
    End If

   
End Sub
 
Isn't "[Employee #]" just a field name in the database and needs to be passed through as a string ?

Untested but try"
Rich (BB code):
        strSQL = defaultSql & " WHERE [Employee #] LIKE '*" & frmPersonnelEntry.txtEmpNum.Text & "*'"
 
Upvote 0

Forum statistics

Threads
1,226,796
Messages
6,193,048
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top