473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Problem in date fields

274 100+
Hello everyone.
I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this.
The problem is:
I want to print account statement (or any other report) from VB form based on an entered date in the masked fields (dd/mm/yy). I am using one form to display five reports. I send date to display report after formatting it (m/dd/yy). When I enter date range like this in masked textbox (DD/MM/YY)

23/10/2007 - 29/10/2007 pls note I get two digit in date after formatting it
the report works fine.
However, on trying dates like this

09/10/2007 - 12/10/2007 note that first date is now 10/9/2007 not the second
or
the output contains all records till date 12/10/2007
23/10/2007 - 06/11/2007 second date is one digit after formatting

I get output with all dates even previous month.... till date 23/10/2007 nothing from next month.

if I use 8/10/2007 - 9/10/2007 both dates one digit dates
I get no records found

I am really worried because I can't understand the reason; here is code I am using (sliced code of the module because its really long)

Form has two date boxes (and 2 masked fields)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. If EndingDate_msk.Visible = False And formcall <> 1 And formcall <> 6 And formcall <> 5 And formcall <> 4 And formcall <> 2 And formcall <> 7 Then ' if closing sheet is calling this form
  3. StartingDate_msk.Text = Format$(Date, "dd/mm/yyyy")
  4. Else
  5.     EndingDate_msk.Text = Format$(DateSerial(Year(Now), Month(Now), 0), "dd/mm/yyyy")
  6.     Dim Yr, Mnth
  7.     If Month(Now) = 1 Then
  8.         Yr = Year(Now) - 1
  9.         Mnth = 12
  10.     Else
  11.         Yr = Year(Now)
  12.         Mnth = Month(Now) - 1
  13.     End If
  14.     StartingDate_msk.Text = Format$(DateSerial(Year(EndingDate_msk.Text), Month(EndingDate_msk.Text), 1), "dd/mm/yyyy")
  15. End If
  16. End Sub

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnView_Click()
  2. On Error GoTo err:
  3. Dim d As String
  4. cfromdate.Text = Format$(StartingDate_msk.Text, "m/dd/yy")
  5. ctodate.Text = Format$(EndingDate_msk.Text, "m/dd/yy")
  6. 'd = StartingDate_msk.Text
  7. d = StartingDate_msk.Text
  8. Dim d1 As String
  9. Dim d4 As String
  10. Dim d5 As String
  11. d1 = (d)
  12. d4 = Mid(d1, 1, 2)
  13. d5 = Mid(d1, 4, 2)
  14. 'validlidate endingdate
  15. Dim dtwo As String
  16. dtwo = EndingDate_msk.Text
  17. 'dtwo = endingdate_mask.Text
  18. Dim d12 As String
  19. Dim d42 As String
  20. Dim d52 As String
  21. d12 = (d)
  22. d42 = Mid(dtwo, 1, 2)
  23. d52 = Mid(dtwo, 4, 2)
  24.  
  25. strTo = Format$(StartingDate_msk.Text, "m/dd/yy")
  26. strFrom = Format$(EndingDate_msk.Text, "m/dd/yy")
  27. ............(sliced)
  28. '*******************************************************
  29. '******           RptAccountStatement         **********
  30. '*******************************************************
  31. ElseIf formcall = 7 Then
  32.  
  33.     If txtAccountNo.Text = "" Then
  34.         MsgBox ("Please select an account no first")
  35.         If txtAccountNo.Enabled = True Then
  36.             txtAccountNo.SetFocus
  37.         End If
  38.         Exit Sub
  39.     End If
  40. strAccountNo = Trim(txtAccountNo.Text)
  41. ''''''''''''''''''''''''''''for single date and a particular account no'''''''''''''''
  42.        If onday_option.Value = True And txtAccountNo.Text <> "" Then
  43.             If (Val(d4) > 31 Or Val(d5) > 12) Or StartingDate_msk.Text = "__/__/____" Then
  44.                     MsgBox ("Please enter a valid date!!!")
  45.                      StartingDate_msk.SetFocus
  46.                      Exit Sub
  47.              Else
  48.                      strSQL = "SHAPE {select distinct vendor.customer,inv_total.account_no,vendor.address,vendor.city ,vendor.province ,vendor.postal_code ,inv_total.date,tran_id,inv_total.po_number,total_amt as t,gst as g,(t+g) as total from inv_total,vendor,product_codes where vendor.account_no=" & strAccountNo & " and inv_total.date = #" & strTo & "# and inv_total.account_no = vendor.account_no}  AS AccountStatement1 APPEND ({select tran_id,product_codes.description,inv_detail.quantity as q1,product_codes.unit_size,inv_detail.price as p1, (p1*q1) as subtotal from inv_detail,product_codes  where inv_detail.item_code=product_codes.item_code }  AS AccountStatement2 RELATE 'tran_id' TO 'tran_id') AS AccountStatement2"
  49.                      strdates = "                For  " + strTo
  50.                         RptAccountStatement.Show 1
  51.              End If
  52.  ''''''''''''''''''''''''''''for two dates and a specified account number''''''''''''''''''''''
  53.         ElseIf Bydates_option.Value = True And txtAccountNo.Text <> "" Then
  54.             If (Val(d4) > 31 Or Val(d5) > 12 Or Val(d42) > 31 Or Val(d52) > 12) Or StartingDate_msk.Text = "__/__/____" Or EndingDate_msk.Text = "__/__/____" Then
  55.                      MsgBox ("Please enter a valid dates for report first")
  56.                      Exit Sub
  57.             Else
  58.                 strSQL = "SHAPE {select distinct vendor.customer,inv_total.account_no,vendor.address,vendor.city ,vendor.province ,vendor.postal_code ,inv_total.date,tran_id,inv_total.po_number,total_amt as t,gst as g,(t+g) as total from inv_total,vendor,product_codes where vendor.account_no=" & strAccountNo & " and inv_total.date between #" & strTo & "# and #" & strFrom & "# and inv_total.account_no = vendor.account_no}  AS AccountStatement1 APPEND ({select tran_id,product_codes.description,inv_detail.quantity as q1,product_codes.unit_size,inv_detail.price as p1, (p1*q1) as subtotal from inv_detail,product_codes  where inv_detail.item_code=product_codes.item_code }  AS AccountStatement2 RELATE 'tran_id' TO 'tran_id') AS AccountStatement2"
  59.                         strdates = "       From  " + strTo + "   to   " + strFrom
  60.                         strtitle = "Vendor History"
  61.                         RptAccountStatement.Show 1
  62.  
  63.             End If
  64.  '''''''''''''''''''for no date criteria and no cat selection'''''''''''''
  65.         ElseIf onday_option.Value = False And Bydates_option.Value = False And txtAccountNo.Text = "" Then
  66.                    MsgBox ("Please Select Any Category and enter a valid date to print a report")
  67.                     Exit Sub
  68.         End If
  69.  
  70. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  71.  
  72.   End If
  73. '''''''''''''''''''''''''''''(sliced)
Please help me solve this problem
Nov 7 '07 #1
7 2075
QVeen72
1,445 Expert 1GB
Hi,

Try to use DatePicker instead of the MaskedTextbox..

Regards
Veena
Nov 7 '07 #2
creative1
274 100+
but i m printing report by using variables
Nov 7 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

Even if you use Variables, after Formatting in the Textbox, the date Values itself are changing as per your post..
Dates are a bit complicated, It again depends on the Regional setting of the User. if user has got m/d/yy format and you have Formatted with dd/mm/yyyy, "m"and "d" are Interchanged for dates 1 to 9..
Date Picker would avoid such Complications..

Regards
Veena
Nov 7 '07 #4
creative1
274 100+
thanks I'll try date picker. I never use it and don't know how it works. If yo any code sample pls send me.
regards
Nov 7 '07 #5
debasisdas
8,127 Expert 4TB
Include Microsoft Windows Common Controls-2 6.0 (SP4) from components .

Then try to use the value property.
Nov 7 '07 #6
creative1
274 100+
when I tried the same code on another machine that had Vista installed on it. I worked fine and not any problem at all.
whats the reason? can someone tell
Nov 8 '07 #7
Killer42
8,435 Expert 8TB
I think the important thing to remember is that the masked edit control just returns a string. So when you try to format that as though it were a date, you force VB to first try and convert it to a date value.

Thus, when you say ctodate.Text = Format$(EndingDate_msk.Text, "m/dd/yy") you are saying to do the following...
  1. Take the string which is in EndingDate_msk.Text and convert it to a date value using whatever defaults are set up on this machine, then
  2. Format that date as "m/dd/yy", returning a string, and then
  3. Place that string in ctodate.Text.
You can see that you have already potentially stuffed up your data in step 1, no matter what you do with it afterward.

There are a number of ways around this sort of problem. One is to use the DatePicker control as has been suggested. Another technique is to use an unambiguous date format when interacting with the user. For example, a format such as "DD-MMM-YYYY" (Eg. "01-JUN-2007") will never be misinterpreted.
Nov 8 '07 #8

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

Similar topics

0
by: Jack | last post by:
I am trying to debug a if else statement by using the following lines of code Response.Write RSreccountCurrentExpense("reccount") & "<br>" If RSreccountCurrentExpense("reccount") < 1 Then...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
4
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
1
by: graemeharnish | last post by:
Hello. I'm trying to mod an open source app called TinyERP and inherit from a parent object, and in essence change how _column is defined. I found sample code of: class...
9
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes...
1
by: swathichavalla | last post by:
Problem description: Clients working with an apple computer with the safari browser are experiencing problems with brokerage orders. When the client wants to enter a stock order, the order entry...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.