By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Default and mandatory field functions

Cyberdyne
Expert 100+
P: 627
I have two fields

Field1 - has options Yes or No
Field2 - has three options to chose from

First: What do I need to do to make Field1 be No and Field2 not selectable by default?

Second: If Field1 is selected as Yes I want Field2 to become selectable and mandatory.

Let me know, Cyberdyne.
Dec 27 '06 #1
Share this Question
Share on Google+
23 Replies


100+
P: 1,646
I have two fields

Field1 - has options Yes or No
Field2 - has three options to chose from

First: What do I need to do to make Field1 be No and Field2 not selectable by default?

Second: If Field1 is selected as Yes I want Field2 to become selectable and mandatory.

Let me know, Cyberdyne.
Hi. Are you thinking about a form?
Dec 28 '06 #2

Cyberdyne
Expert 100+
P: 627
Hi. Are you thinking about a form?


Yes its a form with many fields Field1 and Field2 are the last two fields in the form.
Dec 28 '06 #3

100+
P: 1,646
Yes its a form with many fields Field1 and Field2 are the last two fields in the form.
Then you can make field1 an option group with two radio buttons. When no is selected, as by default, you can make field2 either invisible:
Expand|Select|Wrap|Line Numbers
  1. Field2.Visible = False
or you can disable Field2 so that it is visible and cannot be used
Expand|Select|Wrap|Line Numbers
  1. Field2.Enabled = False
Dec 28 '06 #4

Expert 5K+
P: 8,434
Then you can make field1 an option group with two radio buttons. When no is selected, as by default, you can make field2 either invisible ...
or you can disable Field2 so that it is visible and cannot be used
Seems as though a checkbox would be appropriate for Field1, though radio buttons work too.
Dec 28 '06 #5

Cyberdyne
Expert 100+
P: 627
Ok so how do I do this? All I want is the first field to be visible and defaulted to "No" and the second field to be invisible by default but if the first field is "Yes" I want it to appear and become mandatory.

I created the fields so lets assume I have Field1 and Field2 what would be the code and where do I enter it? I know how to get to event procedure and all.

Let me know guys, thanks!
Dec 28 '06 #6

100+
P: 1,646
Ok so how do I do this? All I want is the first field to be visible and defaulted to "No" and the second field to be invisible by default but if the first field is "Yes" I want it to appear and become mandatory.

I created the fields so lets assume I have Field1 and Field2 what would be the code and where do I enter it? I know how to get to event procedure and all.

Let me know guys, thanks!
Seems like you have ignored the answers above.
What does mandatory mean?
Dec 28 '06 #7

Cyberdyne
Expert 100+
P: 627
I didn't ignore the answers I plugged them in the code but it did nothing

Mandatory meaning that I have to chose one of the options in Field2 in order to continue to next client.
Dec 28 '06 #8

100+
P: 1,646
I didn't ignore the answers I plugged them in the code but it did nothing

Mandatory meaning that I have to chose one of the options in Field2 in order to continue to next client.
OK. Could you post your code with the plugged in items included please?
Dec 28 '06 #9

Cyberdyne
Expert 100+
P: 627
I will pm you the code
Dec 28 '06 #10

100+
P: 1,646
I will pm you the code
Please do not pm code. It is not useful to others who want to learn from solutions to problems.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  
  4. Private Sub ContactTypeID_NotInList(NewData As String, Response As Integer)
  5. MsgBox "Double-click this field to add an entry to the list."
  6. Response = acDataErrContinue
  7. End Sub
  8. Private Sub ContactTypeID_DblClick(Cancel As Integer)
  9. On Error GoTo Err_ContactTypeID_DblClick
  10. Dim lngContactTypeID As Long
  11.  
  12. If IsNull(Me![ContactTypeID]) Then
  13. Me![ContactTypeID].Text = ""
  14. Else
  15. lngContactTypeID = Me![ContactTypeID]
  16. Me![ContactTypeID] = Null
  17. End If
  18. DoCmd.OpenForm "Contact Types", , , , , acDialog, "GotoNew"
  19. Me![ContactTypeID].Requery
  20. If lngContactTypeID <> 0 Then Me![ContactTypeID] = lngContactTypeID
  21.  
  22. Exit_ContactTypeID_DblClick:
  23. Exit Sub
  24.  
  25. Err_ContactTypeID_DblClick:
  26. MsgBox Err.Description
  27. Resume Exit_ContactTypeID_DblClick
  28. End Sub
  29. Private Sub Calls_Click()
  30. On Error GoTo Err_Calls_Click
  31. If IsNull(Me![ContactID]) Then
  32. MsgBox "Enter contact information before making a call."
  33. Else
  34. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  35. DoCmd.OpenForm "Calls"
  36. End If
  37.  
  38. Exit_Calls_Click:
  39. Exit Sub
  40.  
  41. Err_Calls_Click:
  42. MsgBox Err.Description
  43. Resume Exit_Calls_Click
  44. End Sub
  45. Private Sub Dial_Click()
  46. On Error GoTo Err_Dial_Click
  47.  
  48. Dim strDialStr As String
  49. Dim ctlPrevCtl As Control
  50. Const ERR_OBJNOTEXIST = 2467
  51. Const ERR_OBJNOTSET = 91
  52.  
  53. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  54.  
  55. Set ctlPrevCtl = Screen.PreviousControl
  56.  
  57. If TypeOf ctlPrevCtl Is TextBox Then
  58. strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
  59. ElseIf TypeOf ctlPrevCtl Is ListBox Then
  60. strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
  61. ElseIf TypeOf ctlPrevCtl Is ComboBox Then
  62. strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
  63. Else
  64. strDialStr = ""
  65. End If
  66.  
  67. Application.Run "utility.wlib_AutoDial", strDialStr
  68.  
  69. Exit_Dial_Click:
  70. Exit Sub
  71.  
  72. Err_Dial_Click:
  73. If (Err = ERR_OBJNOTEXIST) Or (Err = ERR_OBJNOTSET) Then
  74. Resume Next
  75. End If
  76. MsgBox Err.Description
  77. Resume Exit_Dial_Click
  78. End Sub
  79. Private Sub Page1_Click()
  80. Me.GoToPage 1
  81. End Sub
  82. Private Sub Page2_Click()
  83. Me.GoToPage 2
  84. End Sub
  85.  
  86. Private Sub Client_First_Name_AfterUpdate()
  87. Me![UKey] = Right(Year(Now()), 2) + Nz(DCount("*", "Case#", "UKey Like '" + Right(Year(Now()), 2) + "*'")) + 1
  88. End Sub
  89.  
  90. Private Sub cmdFind_Click()
  91.  
  92.  
  93. Me.Recordset.FindFirst "[Client LN] = " & Nz(Me!txtIdFind, 0)
  94.  
  95. End Sub
  96.  
  97.  
  98.  
  99. Private Sub Is_the_case_workers_comp__BeforeUpdate(Cancel As Integer)
  100. Workers_Comp_Atty.Visible = False
  101. End Sub
  102.  
  103. Private Sub The_date_of_occurence_AfterUpdate()
  104. Me![SOL 1] = DateAdd("yyyy", 1, Me![The_date_of_occurence])
  105. Me![SOL 2] = DateAdd("yyyy", 2, Me![The_date_of_occurence])
  106. Me![SOL 6M] = DateAdd("m", 6, Me![The_date_of_occurence])
  107. End Sub
  108. Private Sub Find_Click()
  109. On Error GoTo Err_Find_Click
  110.  
  111.  
  112. Screen.PreviousControl.SetFocus
  113. DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
  114.  
  115. Exit_Find_Click:
  116. Exit Sub
  117.  
  118. Err_Find_Click:
  119. MsgBox Err.Description
  120. Resume Exit_Find_Click
  121.  
  122. End Sub
  123.  
Your code shows no sign of my suggestions being plugged in.
Would you kindly explain to us what is going on in this routine
Expand|Select|Wrap|Line Numbers
  1. Private Sub Client_First_Name_AfterUpdate()
  2. Me![UKey] = Right(Year(Now()), 2) + Nz(DCount("*", "Case#", "UKey Like '" + Right(Year(Now()), 2) + "*'")) + 1
  3. End Sub
Dec 29 '06 #11

PEB
Expert 100+
P: 1,418
PEB
Ok so how do I do this? All I want is the first field to be visible and defaulted to "No" and the second field to be invisible by default but if the first field is "Yes" I want it to appear and become mandatory.

I created the fields so lets assume I have Field1 and Field2 what would be the code and where do I enter it? I know how to get to event procedure and all.

Let me know guys, thanks!
Hi Cyber,

So for:
All I want is the first field to be visible and defaulted to "No" and the second field to be invisible by default
1.You create ur Field1 and Field2 As Killer suggests you as checkbox or Radio boutons
2.U click on Field1 and open the control properties
3.In the properties form u set up the default Value property to No
4.U cklick on Field2 an open the control properties
5.U set up the Visible property to False

For this part it's all!


if the first field is "Yes" I want it to appear and become mandatory.
For this part:

1.You click on Field1
2.Open the control properties
3.Go onClick property and assign event procedure
4.Type there in the white window:
Expand|Select|Wrap|Line Numbers
  1. Me!Field2.Visible=Me!Field1
  2.  
5.And ur Field2 appears or disapears in function of the value of Field1

Have a very happy new year's eve man!
and very happy year!
Dec 29 '06 #12

PEB
Expert 100+
P: 1,418
PEB
Please do not pm code. It is not useful to others who want to learn from solutions to problems.


Your code shows no sign of my suggestions being plugged in.
Would you kindly explain to us what is going on in this routine
Expand|Select|Wrap|Line Numbers
  1. Private Sub Client_First_Name_AfterUpdate()
  2. Me![UKey] = Right(Year(Now()), 2) + Nz(DCount("*", "Case#", "UKey Like '" + Right(Year(Now()), 2) + "*'")) + 1
  3. End Sub
This is generation of number!
that gets last numbers from the current year,
than gets what is the count of the respective key for the current year and adds 1

:)
Dec 29 '06 #13

100+
P: 1,646
This is generation of number!
that gets last numbers from the current year,
than gets what is the count of the respective key for the current year and adds 1

:)
Oh dear Mr PEB
I do not want to know what this code snippet does. I can see that for myself. I wanted to know if cyberdyne wrote this code or not. I have my doubts

Anyway, PEB, now that you have started I will gladly leave this with you and you can write the validation code to make field2 mandatory.

Have fun :)
Dec 29 '06 #14

Cyberdyne
Expert 100+
P: 627
Hey Guys, the code is cool, I love it when PEB explains things its so straightforward!

Willa the year generation code is to calculate the statue of limitations so once I enter data like 01.01.2007 the statue of limitations for one year will automatically show 01.01.2008 Code was written by PEB because he has been helping me in this first project in access.

Thanks for your help I will try the code and tell you if it works.

Best luck to you all.

Cyberdyne.
Jan 3 '07 #15

Cyberdyne
Expert 100+
P: 627
How do I make row source appear in my checkbox?
Jan 4 '07 #16

NeoPa
Expert Mod 15k+
P: 31,661
What do you mean Cyber?
Are you referring to the 'Control Source' by any chance?
Jan 4 '07 #17

Cyberdyne
Expert 100+
P: 627
Ok I got it now

How can I make field 2 Mandatory? In other words I want it to have a value that a person will choose from the list, but if you don't choose you can't proceed.

let me know thanks
Jan 4 '07 #18

Expert 5K+
P: 8,434
Ok I got it now

How can I make field 2 Mandatory? In other words I want it to have a value that a person will choose from the list, but if you don't choose you can't proceed.

let me know thanks
My guess is you will just need to code that yourself. Probably something like...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   ' If your Field1 checkbox is ticked Then
  3.     ' If you don't like the contents of field2 Then
  4.       Cancel = True
  5.       MsgBox "Get it right, dopey!"
  6.     ' End If
  7.   ' end If
  8. End Sub
Jan 4 '07 #19

Cyberdyne
Expert 100+
P: 627
My guess is you will just need to code that yourself. Probably something like...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   ' If your Field1 checkbox is ticked Then
  3.     ' If you don't like the contents of field2 Then
  4.       Cancel = True
  5.       MsgBox "Get it right, dopey!"
  6.     ' End If
  7.   ' end If
  8. End Sub

Where would I insert this code? In Field1 or Field2 and where in those fields?

So I will right click on the field go to properties go to Event and then in Before Update I will go in to the code and copy and paste that code?
Jan 5 '07 #20

Expert 5K+
P: 8,434
Where would I insert this code? In Field1 or Field2 and where in those fields?

So I will right click on the field go to properties go to Event and then in Before Update I will go in to the code and copy and paste that code?
No, this is the BeforeUpdate event for the form. If this is the correct place for it (it was just a suggestion, after all) you would need to set the Before Update event on the form to [Event Procedure]. Then click the ... to go to the code editor, and insert this code. Note that the procedure declaration (the Private Sub and End Sub lines) will already be filled in, so skip those.

Also, I hope you realise that this code won't run as-is. A lot of it is made up of comments simply showing where to put your code. For example, where it says ' If your Field1 checkbox is ticked Then you need to put the code to test the checkbox.
Jan 5 '07 #21

Cyberdyne
Expert 100+
P: 627
I got it, its working fine, I am able to make it appear once I check field one. For some reason its still not mandatory though, I can still continue onto the next entry without the "Please Enter the name of the User for Field 2"

Any suggestions?
Jan 10 '07 #22

Expert 5K+
P: 8,434
I got it, its working fine, I am able to make it appear once I check field one. For some reason its still not mandatory though, I can still continue onto the next entry without the "Please Enter the name of the User for Field 2"
Can you post the code, so we can see exactly how you implemented it? It usually turns out to be some teeny little detail that's slightly different, so you need to see the actual code to find it.
Jan 10 '07 #23

P: 36
Hope I understand you correctly: Lets add Field3, Field4 and Field5
Set Field2-5 to

Enabled=False
Locked=True
'and
Me.Field1="No"

then on AfterUpdate event of Field1 put this:
Expand|Select|Wrap|Line Numbers
  1. If me.Field1.value="Yes" then
  2.  me.Field2.Enabled=True
  3.  me.Field2.Locked=False
  4. else
  5.  me.Field2.Enabled=false
  6.  me.Field2.Locked=true
  7. end if
then put this on AfterUpdate event of Field2:
Expand|Select|Wrap|Line Numbers
  1. If not isnull(me.field2) then
  2. ' enable and unlock the rest of the fields
  3. end if
The above will really force the user user to enter value in Field2 before going to other fields but if the user select "No" then no data entry will happen or just the Field1 will be filled-in.

HTH,
George



I have two fields

Field1 - has options Yes or No
Field2 - has three options to chose from

First: What do I need to do to make Field1 be No and Field2 not selectable by default?

Second: If Field1 is selected as Yes I want Field2 to become selectable and mandatory.

Let me know, Cyberdyne.
Jan 11 '07 #24

Post your reply

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