473,508 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run Time Error 13 when compare two string formats help

6 New Member
All I am trying to do is based on month value of date typed in 2 unbound form text boxes assign it to summer,winter or mixseason.

I am getting a runtime erro 13 from the statement below.

When I debug both mStart and strJan etc(months) appear as string. I am not sure

where I am going wrong. Please help

Private Sub txtSeason_Click()



Dim mStart As String
Dim mEnd As String

Dim strJan As String
Dim strFeb As String
Dim strMar As String
Dim strApr As String
Dim strMay As String
Dim strJun As String
Dim strJul As String
Dim strAug As String
Dim strSep As String
Dim strOct As String
Dim strNov As String
Dim strDec As String


strJan = "Jan"
strFeb = "Feb"
strMar = "Mar"
strApr = "Apr"
strMay = "May"
strJun = "Jun"
strJul = "Jul"
strAug = "Aug"
strSep = "Sep"
strOct = "Oct"
strNov = "Nov"
strDec = "Dec"


mStart = Format(txtmStartDate.Value, "mmm")


mEnd = Format(txtmEndDate.Value, "mmm")

'IF MONTHSTART AND MONTHEND IN WINTER MONTHS
If ((CStr(mStart) = (strJan) Or (strFeb) Or (strMar) Or (strApr) Or (strNov) Or (strDec))) And ((CStr(mEnd)) = (strJan) Or (strFeb) Or (strMar) Or (strApr) Or (strNov) Or (strDec))) Then
txtSeason.Value = "Winter"

'MONTHSTART AND MONTHEND IN SUMMER MONTHS
ElseIf (CStr(mStart)) = (strMay) Or (strJun) Or (strJul) Or (strAug) Or (strSep) Or (strOct)) And (CStr(mEnd)) = (strMay) Or (strJun) Or (strJul) Or (strAug) Or (strSep) Or (strOct)) Then

txtSeason.Value = "Summer"

'Else MONTH END AND MONSTART NOT EQUAL SAME
'txtSeason = "MixSeason"
End If
Jul 20 '08 #1
2 1779
nico5038
3,080 Recognized Expert Specialist
Hmm, this testing will only work for a period less or equal to half a year.
E.g. Jan 2007 till Jan 2008 should be mixed I guess...

Better to start with testing the number of months between the start and end. > 6 is always mixed.

Next you could use:
Expand|Select|Wrap|Line Numbers
  1. IF datediff("M",Me.txtDateFrom,Me.txtDateTo) > 6 then
  2.   Me.txtSeason= "MixSeason"
  3. ELSE
  4.   IF Month(DateFrom) between 11 and 12 or Month(DateFrom) between 1 and 4 then
  5.      ' possibly winter
  6.     IF Month(DateTo) between 11 and 12 or Month(DateTo) between 1 and 4 then
  7.       Me.txtSeason= "Winter"
  8.     else
  9.       Me.txtSeason= "MixSeason"
  10.     end if
  11.   else
  12.     ' possibly summer
  13.     IF Month(DateTo) between 5 and 10 then
  14.       Me.txtSeason= "Summer"
  15.     else
  16.       Me.txtSeason= "MixSeason"
  17.     end if
  18.   end if
  19. end if
  20.  
Getting the idea ?

Nic;o)
Jul 20 '08 #2
missinglinq
3,532 Recognized Expert Specialist
A major flaw with your code is your comparison syntax.

Expand|Select|Wrap|Line Numbers
  1. If ((CStr(mStart) = (strJan) Or (strFeb) Or (strMar)...
needs to be

If ((CStr(mStart) = (strJan) Or CStr(mStart) = (strFeb) Or CStr(mStart) = (strMar)...

and so forth.

Welcome to Bytes!

Linq ;0)>
Jul 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
9425
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
4
5343
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
5553
by: jty202 | last post by:
I have string that contains a date in this format (14-Jan-05). I want to store in date object if theres one and access each part of the date (month, year, dates, day of week). Specifically I...
9
3214
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database...
15
18861
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
6
2118
by: Maileen | last post by:
Hi, I have the following code : Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String, ByVal EdPeriod As String, ByVal TaskType As String) As Integer Dim strtest As String Dim...
3
2013
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And...
0
9768
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
2
2661
by: horlbecm | last post by:
I am having a problems in with relation to time formats and would greatly appreciate any help. The excel file I am writing the code for uses a Userform to prompt the user to select a file with...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.