Solved

Add a month to the date entered in a msflexgrid i get type mismatch

Posted on 2013-10-22
11
441 Views
Last Modified: 2013-10-22
I get error: Type mismatch
How can i write this:
Dim LastMonth As Date

LastMonth = gridHouse.TextMatrix(gridHouse.Rows - 1, 1)

In the msflexgrid date is like this:May/2013
0
Comment
Question by:isnoend2001
[X]
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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 300 total points
ID: 39592662
Try this.  You need to cast the text as a date data type.
LastMonth = CDate(gridHouse.TextMatrix(gridHouse.Rows - 1, 1))

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39592734
Thanks : aikimark, but still the same error: error13 type mismatch
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 300 total points
ID: 39592760
please verify the contents of that cell
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:isnoend2001
ID: 39592792
already did just to be sure
 MsgBox gridHouse.TextMatrix(gridHouse.Rows - 1, 1)
returns Aug\2014
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
ID: 39592822
"Aug\2014" can't be converted to a date.

Try:
LastMonth = Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\","")

Open in new window

0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 100 total points
ID: 39592825
Which is it
In the msflexgrid date is like this:May/2013

or

returns Aug\2014

Note the direction of the slashes.
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
ID: 39592834
I see that a space got lost in my code (third Replace argument)

It should have been:
LastMonth = Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\"," ")
0
 
LVL 45

Accepted Solution

by:
aikimark earned 300 total points
ID: 39592847
If it is a backslash, instead of the front slash you originally posted, you can do something similar to what GrahamSkan suggested and change the backslash character.
LastMonth = CDate(Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\","/"))

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39592852
backslash (\)
LastMonth = Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\", "") returns the same error
see grid attached
mismatch-error.jpg
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39592862
Sorry. My first comment had a typo in the code. The second version should work.
0
 

Author Closing Comment

by:isnoend2001
ID: 39592872
Thanks that fixes it
LastMonth = CDate(Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\","/"))
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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