Results 1 to 4 of 4
  1. #1
    CevinMoses is offline Novice
    Windows XP Access 2000
    Join Date
    Oct 2010
    Posts
    3

    Thumbs down FileSearch LastModified Type Mismatch

    Using MS-Access 2000, I have a form which searches a specified directory for text files (hyphen delineated) which are then imported into a table so that order information can be extracted.



    Dim stFileName As String
    Dim stDateFilter As String
    Dim Folder As String

    stDateFilter = DLookup("[msoDateFilter]", "[tMsoDateFilter]", "[DateFilter] = '" & Me.DateFilter & "'")

    Application.FileSearch
    .NewSearch
    stFileName = Nz(Me.TxtFilter, "") & "*." & Nz(Me.TxtExtension, "") & "*"
    .FileName = stFileName
    .LastModified = stDateFilter
    .LookIn = Folder
    .Execute

    I want to narrow the search according to a time frame, and .LastModified works fine if I hard code it in, like "msoLastModifiedToday", but when I tried to use a variable, using the DLookup above, the variable comes up with the correct value (stDateFilter = "msoLastModifiedToday") but I get a "Run-time Error 13, Type mismatch" at that line.

    Is there a problem with using a variable for that line, or am I doing something wrong? I tried running stDateFilter as a Variant, but that had no effect.

    -Cevin

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I 've never use file search but I am quite sure LastModified is a date/time type. But your stDateFilter is a string. So, "type mismatch".

  3. #3
    CevinMoses is offline Novice
    Windows XP Access 2000
    Join Date
    Oct 2010
    Posts
    3
    That would make sense, but when you type in ".LastModified = ", VB automatically gives you the following options:

    .LastModified = msoLastModifiedAnyTime
    .LastModified = msoLastModifiedLastMonth
    .LastModified = msoLastModifiedLastWeek
    .LastModified = msoLastModifiedToday
    .LastModified = msoLastModifiedThisMonth
    .LastModified = msoLastModifiedThisWeek
    .LastModified = msoLastModifiedYesterday

    So it should accept the code, unless the mso... actually is a system variable for a date manipulation which sets the range. I'll try that and repost the results.

    -Cevin

  4. #4
    CevinMoses is offline Novice
    Windows XP Access 2000
    Join Date
    Oct 2010
    Posts
    3

    Talking

    Solved it, thanks for the tip. Each constant ("msoLastModified...") can be replaced by its numeric equivalent, and therefore changed based on the combo box like I described. By changing the hard coding and running a line that said:

    Debug.Print "LastModified = " & .LastModified

    I was able to figure out the numeric equivalent for each one. So, my new table for the DLookUp looks like this:

    DateFilter msoDateFilter
    All 7
    Last Month 5
    Last Week 3
    This Month 4
    This Week 6
    Today 2
    Yesterday 1

    I also changed stDateFilter to be an integer. Then it works fine. Hope this helps someone else.

    -Cevin

Please reply to this thread with any new information or opinions.

Similar Threads

  1. type mismatch in expression
    By lilg1924 in forum Database Design
    Replies: 3
    Last Post: 10-06-2010, 01:37 AM
  2. Type mismatch
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 08-07-2010, 06:54 AM
  3. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 PM
  4. Type mismatch in expression /Query
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 04-22-2010, 10:00 AM
  5. Type Mismatch - HELP!
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-17-2009, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums