Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access 2007 DLookup Autonumber Type mismatch Error

Posted on 2008-10-09
5
1,620 Views
Last Modified: 2013-12-20
Hello Experts!

This is an application for employees to schedule a conference room for meetings.  There are several conference rooms; the forms allows the user to pick a conference room from a combo box, there is a list box in turn that lists the scheduled dates for that conference room.  When the user clicks on a date, it populates text boxes on the side with the information of who scheduled it, when it was scheduled, etc.

My problem is displaying the employee name.  I have an Employees table and a Data table.  Each employee has an ID on the Employees table, the Data table stores that ID under the employee field.  The ID itself is a regular Autonumber (Long integer).  I've included my code; I don't understand why I keep getting type mismatch!
Private Sub lboDates_Click()
 
    Dim lngEmployee As Long
                       
    lngEmployee = DLookup("[Employee]", "[tblData]", "[Room]='" + Me.cboRoom.Column(1) + "'") 'This DLookup works fine, returns a long with the correct Employee ID
    
    Dim strEmployeeName As String
        
    strEmployeeName = DLookup("[FirstName]", "[tblEmployees]", "[ID]=" + lngEmployee) 'Here is where the error occurs. I've tried adding single quotes before and after, but that still won't do anything.
    
    MsgBox (strEmployeeName) 'This is just a test MsgBox to see if it works.  I always get the error before getting to this point.
 
End Sub

Open in new window

0
Comment
Question by:PCFIX-IT
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22679706
Try this change (what happens if FirstName is empty in your table, of cannot be found with that ID?)


    Dim strEmployeeName As Variant
        
    strEmployeeName = DLookup("[FirstName]", "[tblEmployees]", "[ID]=" + lngEmployee) 'Here is where the error occurs. I've tried adding single quotes before and after, but that still won't do anything.
    If strEmployeeName is Nothing then
        MsgBox "Cannot find the employee First Name for ID = " & lngEmployee, vbOkOnly
    Else
        MsgBox strEmployeeName
    End If

Open in new window

0
 

Author Comment

by:PCFIX-IT
ID: 22679868
Thanks for the quick reply; I tried that and I get the same "Run-time Error '13' Type mismatch"

I think if the problem was that the record is null I'd be getting a Null Value error; I think it has to do with the Autonumber for some reason but that might be me being stubborn.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22680470
ok, should have been

    If IsNull(strEmployeeName) Then
        MsgBox "Cannot find the employee First Name for ID = " & lngEmployee, vbOkOnly
    Else
        MsgBox strEmployeeName
    End If
0
 

Author Comment

by:PCFIX-IT
ID: 22681085
Thanks again for the quick reply Arthur,

That code still gives me the same Error as the other; right now the data in my tables is really limited as it's only test data; I know the ID and First Names I'm looking for exist and the ID is being picked up correctly.  

The issue is not that it returns null values, it's the the ID field on the tblEmployees table keeps telling me there's a type mismatch even though I'm using a Long Integer for the DLookup.
0
 

Accepted Solution

by:
PCFIX-IT earned 0 total points
ID: 22682387
The solution was to change the syntaxt on the DLookup; instead of using "+" I changed it to "&" and it worked!

strEmployeeName = DLookup("[FirstName]", "[tblEmployees]", "[ID]=" & lngEmployee)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question