prevent users from entering data

rkaria

Registered User.
Local time
Today, 17:57
Joined
Nov 19, 2009
Messages
48
Hi All

I have a form which requires users to enter dates in several fields.

I have got it so they select a date from the calender, but i would like it so they cant enter the date manually and they have to enter the date via the calender.

Can anyone advise me how to do this please?

Access 2003

Thanks
R
 
Disable the text box and set its CONTROL SOURCE property to the Calendar Control.
 
Disable the text box and set its CONTROL SOURCE property to the Calendar Control.


I have tried this and makes not difference as the text box is disable and nothing can be selected.
 
Last edited:
If the calendar is entering the data to the text box with code then locking the text box will not affect the calendar in any way.

To lock the text box just go to the form in design view, select the control, go to the properties dialog and then under the DATA tab just select YES for the LOCKED property.
 
having said that, it seems a strange request

most users like to be able to use keyboards - generally you find things going the other way - eg how do i open a drop down by keyboard alone?
 
having said that, it seems a strange request

most users like to be able to use keyboards - generally you find things going the other way - eg how do i open a drop down by keyboard alone?


I know, you would think so wouldnt you but it seems that users dont know how to enter date properly!!!! so I thought to make it easier for them they can enter dates from the calendar.

They are inputting 2020 instead of 2010 or 120 instead of....I dont know really, think they are not checking and typing in fast.
 
In light of the new information, instead of locking/disabling you can validate the date before it gets saved.

1. In design view, click the control and open up its PROPERTY SHEET.
2. Select the EVENT tab, put click inside the BEFORE UPDATE event.
3. Click the command button button that appears, it should have three dots (an elipsis), click that.
4. Put the code highlighted in blue and substitute the textbox name in the code with yours (highlighted in green).

Code:
Private sub txtDate_[COLOR=Red][B]BeforeUpdate(cancel as integer)[/B][/COLOR]
[COLOR=Blue]    if isdate() = false then 
         cancel = true
         [COLOR=DarkGreen]txtdate[/COLOR].value = ""
         [COLOR=DarkGreen]txtdate[/COLOR].setfocus
         msgbox "Invalid date"
    else
         if year(txtdate.value) <> year(date()) then
              cancel = true
              [COLOR=DarkGreen]txtdate[/COLOR].value = ""
             [COLOR=DarkGreen] txtdate[/COLOR].setfocus
              msgbox "Incorrect date.", vbexclamation, "Incorrect date"
         end if
    end if[/COLOR]
End sub
 
In light of the new information, instead of locking/disabling you can validate the date before it gets saved.

1. In design view, click the control and open up its PROPERTY SHEET.
2. Select the EVENT tab, put click inside the BEFORE UPDATE event.
3. Click the command button button that appears, it should have three dots (an elipsis), click that.
4. Put the code highlighted in blue and substitute the textbox name in the code with yours (highlighted in green).

Code:
Private sub txtDate_[COLOR=red][B]BeforeUpdate(cancel as integer)[/B][/COLOR]
[COLOR=blue]   if isdate() = false then [/COLOR]
[COLOR=blue]        cancel = true[/COLOR]
[COLOR=blue]        [COLOR=darkgreen]txtdate[/COLOR].value = ""
         [COLOR=darkgreen]txtdate[/COLOR].setfocus
         msgbox "Invalid date"
    else
         if year(txtdate.value) <> year(date()) then
              cancel = true
              [COLOR=darkgreen]txtdate[/COLOR].value = ""
             [COLOR=darkgreen]txtdate[/COLOR].setfocus
              msgbox "Incorrect date.", vbexclamation, "Incorrect date"
         end if
    end if[/COLOR]
End sub

Thanks for this, but the date may be any dates between 2004 till present. This coding would only allow me to enter the current year's date.
 
I suggest you stick with using the calander popup control and lock the date field as previously suggested.
 

Users who are viewing this thread

Back
Top Bottom