Normal Topic @calendar for search mode entry (Read 558 times)
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
@calendar for search mode entry
Jun 8th, 2010 at 12:30pm
Print Post Print Post  
I’ve been successful modifying this code so that the client can use the calendar pop-up to enter a date range into a date field while in search mode rather than having to type it manually.  It works like this; when the code is tied to a command button, the first click opens the calendar, and the choice is placed in the designated LE. Then a @MSGBOX informs the user to press ok and then select the ending date for the range desired.  It works great and places the dates in the LE like this: “01/01/2010..03/31/2010” and then the user can retrieve the matching records.  The problem I’m having is that if the user only wants to select one date instead of a range and they press ESC to exit the second calendar, ESC enters a strange number into the LE.  The number contains the first date selected, ie., “01/01/2010” plus “..2969203/03/26”.   This number “..296923/03/26” appears to be the same no matter what first date is selected.  A work around would be for the user to enter the same date twice to search, for example “01/01/2010..01/01/2010”.

Is there way to modify the code so that when ESC is pressed for the second calendar that it leaves the designated LE with only the first date?

Thanks for your help.
[code]
var MyDate as String
var vDate1 as String
var vDate2 as String

If @Mode() = 2 Then
{
     If @isblank(EntryDate)
     myDate = @Calendar("", "Select a Beginning Date (Esc to Cancel)")
     If Not @Error
     MyDate = @Right(MyDate, 5) + "/" + @Left(MyDate, 4)
     FormFieldValue(@Layout + ":(Search)", "EntryDate", 0, MyDate)
}

If @Mode() = 2 Then
{
@MSGBOX("","For a date range, Press OK and then select an ending date","Otherwise press OK then ESC")
}

If @Mode() = 2 and not @isblank(EntryDate)
{
     vDate1 = @Right(EntryDate, 5) + "/" + @Left(EntryDate, 4)
     vDate2 = @Calendar("", "Select an Ending Date (Esc to Cancel)")
     If Not @Error
     vDate2 = @Right(vDate2, 5) + "/" + @Left(vDate2, 4)
     FormFieldValue(@Layout + ":(Search)", "EntryDate", 0, vDate1  + ".." + vDate2)
}

Else

{
EntryDate = @Calendar("", "Select A Date (Esc to Cancel)")
}

[/code]
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @calendar for search mode entry
Reply #1 - Jun 8th, 2010 at 2:00pm
Print Post Print Post  
In this bit of code:
Code
Select All
	If @isblank(EntryDate)
	myDate = @Calendar("", "Select a Beginning Date (Esc to Cancel)")
	If Not @Error
	MyDate = @Right(MyDate, 5) + "/" + @Left(MyDate, 4)
	FormFieldValue(@Layout + ":(Search)", "EntryDate", 0, MyDate)
 



you will see that the @Calendar function gets called only if the EntryDate is blank, but all of the rest of the code is executed. This is because a conditional ("if statement") is going to run only the next line, unless it has curly braces following it to indicate which lines should be contained in the condition. To avoid this, I usually contain even a single line in curly braces - for clarity.

I suspect you may be intending something more like this:
Code
Select All
If @isblank(EntryDate)
{
        myDate = @Calendar("", "Select a Beginning Date (Esc to Cancel)")
        If Not @Error
        {
                MyDate = @Right(MyDate, 5) + "/" + @Left(MyDate, 4)
                FormFieldValue(@Layout + ":(Search)", "EntryDate", 0, MyDate)
        }
}

 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: @calendar for search mode entry
Reply #2 - Jun 8th, 2010 at 2:33pm
Print Post Print Post  
The programming below may also help you get what you are after:
Command Button :: On Element Entry
Code
Select All
var vDate1 as Date
var vDate2 as Date
var vDateRange as String
var vConfirm as Int

If @Mode() = 2 Then
	{
		vDate1 = @Calendar("","Select Start Date")
		vConfirm = @AskUser("Do you want to select an end date in the future?", "Choose Yes to select an end date.","Choose No for a start date only.")
		If vConfirm = 1 Then
			{
				vDate2 = @Calendar("","Select End Date")
				If Not @Error
					{
						vDateRange = vDate1 + ".." + vDate2
					}
			}
		Else
			{
				vDateRange = vDate1 + ".." + vDate1
			}

		FormFieldValue(@Layout, "EntryDate", 1, vDateRange)
	}

 


Form :: On Form Entry
Code
Select All
If @Mode() = 2 Then
{
		Visibility(Command Button, 1)
}
Else
{
		Visibility(Command Button, 0)
}
 



  
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @calendar for search mode entry
Reply #3 - Jun 8th, 2010 at 5:55pm
Print Post Print Post  
Thank you very much Mark, putting curly braces in the right places solved the trouble. I hate to admit it but as you can see I'm lacking in fully understanding curly braces.  Your explanation tho has helped greatly.

Thank you Ben for your code. I have to say your method is sure prettier than mine and works better.  I think I'll be using it instead.

Thanks again to the both of you.

Brandon
  
Back to top
IP Logged