Solved

Query def return error a mismatch but still creates the query

Posted on 2014-09-10
4
262 Views
Last Modified: 2014-09-10
I have the below procedure, but when it hits the query def, I get Run-time error 13, Type mismatch.  But it does create the query properly.  I do not understand why it would create the query, yet error out at the query def statement.

Public Sub CheckImportDates()
'checks to see if there are importID's for employee.  If not, adds
'the ImportId information to the table
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstTable As DAO.Recordset
Dim strDoesNotExist As String
Dim qdfDoesNotExist As QueryDef

strDoesNotExist = "SELECT DISTINCT tblTEMPImport.ImportID, tblTEMPImport.[Last Name], " & _
    "tblTEMPImport.[First Name], tblTEMPImport.Project " & _
    "FROM tblTEMPImport " & _
    "WHERE (((Exists (SELECT ImportID, [Last Name], [FirstName], ProjectName " & _
    "FROM tblImportedMonths " & _
    "WHERE  tblTEMPImport.ImportID= tblImportedMonths.ImportID AND " & _
    "tblTEMPImport.[First Name] = tblImportedMonths.FirstName AND " & _
    "tblTEMPImport.[Last Name] = tblImportedMonths.LastName AND " & _
    "tblTEMPImport.Project = tblImportedMonths.ProjectName))=False)) "

Set dbs = CurrentDb
Set rst = dbs.CreateQueryDef("qryDoesNotExist", strDoesNotExist)  "ERRORS OUT HERE
Set rstTable = dbs.OpenRecordset("tblImportedMonths", dbOpenTable)

If rst.RecordCount > 0 Then
    rst.MoveFirst
    Do While Not rst.EOF
        rstTable.AddNew
        rstTable!ImportID = rst!ImportID
        rstTable!LastName = rst![Last Name]
        rstTable!FirstName = rst![First Name]
        rstTable!Properties = rst!Project
        rstTable.Update
        rst.MoveNext
   Loop
Else
    'do Nothing
End If



rst.Close
rstTable.Close

Set rst = Nothing
Set rstTable = Nothing
Set dbs = Nothing

End Sub

Sandra
0
Comment
Question by:ssmith94015
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40315794
change this

Set rst = dbs.CreateQueryDef("qryDoesNotExist", strDoesNotExist)

with


Set qdfDoesNotExist = dbs.CreateQueryDef("qryDoesNotExist", strDoesNotExist)
0
 

Author Comment

by:ssmith94015
ID: 40315815
The below should then set the rst to qdfDoesnoteExist?

Set qdfDoesNotExist = dbs.CreateQueryDef("qryDoesNotExist", strDoesNotExist)
Set rst = qdfDoesNotExist
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40315825
Set qdfDoesNotExist = dbs.CreateQueryDef("qryDoesNotExist", strDoesNotExist)

 Set rst = qdfDoesNotExist.openrecordset
0
 

Author Closing Comment

by:ssmith94015
ID: 40315830
Thank you.  Got over that hurdle.  Am posting another question as it now stops at the statement trying to open the table!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

830 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