473,387 Members | 1,379 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,387 software developers and data experts.

Validation that only allows Weekdays!

36
I am trying to restrict the user to only enter date which is weekdays. so, it shouldn't allow a date that is weekend such as 08/04/07 (Sunday). Can someone help me with this issue. In short i want the user to enter a date which is Monday, Tuesday, Wednesday, thursday and Friday!

Additionally, i'm new to Databases so, could you tell me whether the validation rule given should be used during table design or on the form date field. Any help would be much appreciated.
Apr 9 '07 #1
8 4698
pks00
280 Expert 100+
ok, assuming this all done via a form
say u had a field called txtDate, this is where the user enters a date
each control have a number of event handlers, kinda like triggers in oracle

in access, txtboxes have a beforeupdate event handler, this allows u to validate and abort the update
to get the weekday, u can use the WeekDay function


so for example

Expand|Select|Wrap|Line Numbers
  1. private sub txtDate_BeforeUpdate(Cancel as Integer)
  2.  
  3.     Dim iWeekNo as integer
  4.  
  5.     iWeekNo = WeekDay(txtDate) 
  6.     if iWeekNo = 1 or iWeekNo = 7 then  '1=sunday,7=saturday
  7.         cancel = true       'set to true to abort update
  8.         msgbox "Please enter mon-fri date"
  9.     end if
  10. end sub
  11.  
Apr 10 '07 #2
atiq
36
It's you again! again u've sorted the problem, ur awesum a natural genueis u r! this was probably a piece of cake for u.

another thing i wanted to know is, how to automatically open a form based on a selected value in a combo box. In short, if da user selects 'Contact Parent' then i want it to automatically open another form.

Once again thanks for helping me out.
Apr 10 '07 #3
pks00
280 Expert 100+
Hello again, happy to help out

Regarding your other question, u need to make use of the event handler called AfterUpdate. This is called each time a change is made

eg u have a combobox called cboMyCombo (it could be a textbox also, doesnt matter)

private sub cboMyCombo_AfterUpdate()
if Me.cboMyCombo = "Contact Parent" then
DoCmd.OpenForm "new form"
end if
end sub
Apr 11 '07 #4
atiq
36
Hello again, happy to help out

Regarding your other question, u need to make use of the event handler called AfterUpdate. This is called each time a change is made

eg u have a combobox called cboMyCombo (it could be a textbox also, doesnt matter)

private sub cboMyCombo_AfterUpdate()
if Me.cboMyCombo = "Contact Parent" then
DoCmd.OpenForm "new form"
end if
end sub
I tried using this code but nothing seems to happen.it doesn't even display any error message! the name of the combo box is cmbAction and i even tried using this code:

Private Sub cmbAction_AfterUpdate()

If Me.cmbAction = "Contact Parents" Then
DoCmd.OpenForm "frmSendEmail", acNormal, acFormEdit, acWindowNormal
End If

End Sub


In addition to this, for the same combo box i want the command button named cmdPrintDetentionSlip to be visible if the value Detention is selected.

Hope u can make my day today as well!
Apr 12 '07 #5
pks00
280 Expert 100+
How many columns do u have in your combo?

try this to see what is selected

Private Sub cmbAction_AfterUpdate()

msgbox "Selected is >" & Me.cmbAction & "<"

If Me.cmbAction = "Contact Parents" Then
DoCmd.OpenForm "frmSendEmail", acNormal, acFormEdit, acWindowNormal
End If

End Sub


when u run it, what is displayed in the message box
Apr 12 '07 #6
atiq
36
How many columns do u have in your combo?

try this to see what is selected

Private Sub cmbAction_AfterUpdate()

msgbox "Selected is >" & Me.cmbAction & "<"

If Me.cmbAction = "Contact Parents" Then
DoCmd.OpenForm "frmSendEmail", acNormal, acFormEdit, acWindowNormal
End If

End Sub

when u run it, what is displayed in the message box
The message displayed is Selected is >4<
Apr 12 '07 #7
pks00
280 Expert 100+
this means that u are using multiple columns in your combo
what is the sql for the combo

if the description is the 2nd field in the combo, then try this

if cmbAction.Column(1) = "Contact Parents" then


cmbAction.Column(0) refers to first column, in this case, most likely 4
cmbAction.Column(1) refers to second column
cmbAction.Column(2) refers to third column etc

eg
select f1, f2, f3
from mytable

column(0) = f1
column(1) = f2
etc
Apr 12 '07 #8
pks00
280 Expert 100+
Assuming its the 2nd column


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbAction_AfterUpdate()
  2.  
  3.     cmdPrintDetentionSlip.Visible = False
  4.     If Me.cmbAction.Column(1) = "Contact Parents" Then
  5.         DoCmd.OpenForm "frmSendEmail", acNormal, acFormEdit, acWindowNormal
  6.     Elseif Me.cmbAction.Column(1) = "Detention" then
  7.         cmdPrintDetentionSlip.Visible = True
  8.     End If
  9.  
  10. End Sub
  11.  

Normal practice, its not good to use hardcoding of description names as they are subject to change, better to check against the numbers
Apr 12 '07 #9

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

Similar topics

2
by: Tiernan | last post by:
Hi all I'm looking for a way to find the number of weekdays between 2 dates In my form I have three fields for a begin date (dd)(mm)(yyyy) and three for the end date (dd)(mm)(yyyy) Now these...
3
by: elaines | last post by:
I can't seem to get this to work. Any help appreciated. The alert message always comes up. Here is my code <SCRIPT type="text/javascript"> function fte() { var hours =...
23
by: Ash | last post by:
Hi everyone, This problem has been puzzling me for a fair time now, and has severely frustrated me!! Perhaps I'm just not getting the syntax right, but the problem is rather simple... Take a...
2
by: Matt Mercer | last post by:
Hi, My first post here. I am a self-taught, very "green" web developer. It is not the main focus of my job but required from time to time. I am developing a web application that logs security...
5
by: M | last post by:
Hi, it's possible to append a custom action to a client-side verification of a validation control ? I have a validator summary control that shows (automatically) a message box if the validation...
5
by: Sun Jian | last post by:
Hi, I am trying to customize the asp.net validation to achieve the following: Upon submitting the form, client side validation will run, and it will stop at the first error detected. For...
6
by: serge calderara | last post by:
Dear all, I have read that ASP.NET does double user input validation of control when they are place on the page. Once on teh client side and again from server side right ? Could explain how...
4
by: MLH | last post by:
I'm thinking of an integer field in which I could write values up to 1+2+4+8+16+32+64 and to use these values later. Each of the individual values would represent a weekday from Sunday to Saturday....
7
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...

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.