Solved

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

Posted on 2013-10-22
11
432 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
  • 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
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.

 

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 46

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: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

820 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