• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

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

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
isnoend2001
Asked:
isnoend2001
  • 4
  • 3
  • 3
  • +1
6 Solutions
 
aikimarkCommented:
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
 
isnoend2001Author Commented:
Thanks : aikimark, but still the same error: error13 type mismatch
0
 
aikimarkCommented:
please verify the contents of that cell
0
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.

 
isnoend2001Author Commented:
already did just to be sure
 MsgBox gridHouse.TextMatrix(gridHouse.Rows - 1, 1)
returns Aug\2014
0
 
GrahamSkanRetiredCommented:
"Aug\2014" can't be converted to a date.

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

Open in new window

0
 
Martin LissOlder than dirtCommented:
Which is it
In the msflexgrid date is like this:May/2013

or

returns Aug\2014

Note the direction of the slashes.
0
 
GrahamSkanRetiredCommented:
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
 
aikimarkCommented:
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
 
isnoend2001Author Commented:
backslash (\)
LastMonth = Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\", "") returns the same error
see grid attached
mismatch-error.jpg
0
 
GrahamSkanRetiredCommented:
Sorry. My first comment had a typo in the code. The second version should work.
0
 
isnoend2001Author Commented:
Thanks that fixes it
LastMonth = CDate(Replace(gridHouse.TextMatrix(gridHouse.Rows - 1, 1), "\","/"))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now