Hello,
I have a form that has some controls whose properties are already listed as required in the table, as they are always enabled. The form also has a combo box labeled "Outcome" that changes other textboxes to be enabled depending on what is chosen in that combo box. What I would like to do, is make sure that whatever textboxes are enabled are also required. Is this possible? Here is my code for the Outcome combo box - Private Sub Outcome_Change()
-
If [Outcome] = "Pending" Then
-
[Date Provided].Enabled = False
-
[Date Provided] = Null
-
[Providers].Enabled = False
-
[Providers] = Null
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = False
-
[Time] = Null
-
[Cost].Enabled = False
-
[Cost] = Null
-
[Comments].Enabled = True
-
Else
-
If [Outcome] = "Interpretation" Then
-
[Date Provided].Enabled = True
-
[Providers].Enabled = True
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = True
-
[Comments].Enabled = True
-
Else
-
If [Outcome] = "Translation" Then
-
[Date Provided].Enabled = True
-
[Providers].Enabled = True
-
[Number of Pages].Enabled = True
-
[Time].Enabled = True
-
[Comments].Enabled = True
-
Else
-
[Date Provided].Enabled = False
-
[Date Provided] = Null
-
[Providers].Enabled = False
-
[Providers] = Null
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = False
-
[Time] = Null
-
[Cost].Enabled = False
-
[Cost] = Null
-
[Comments].Enabled = True
-
End If
-
End If
-
End If
-
End Sub
10 1506
Elaine,
I would use a Select Case Statement for your Combo Box, which prevents the eternal nesting of If...Then statements. This would also make it easier to add additional values to your combo box.: - Private Sub Outcome_Change()
-
Select Case Outcome
-
Case "Pending"
-
[Date Provided].Enabled = False
-
[Date Provided] = Null
-
[Providers].Enabled = False
-
[Providers] = Null
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = False
-
[Time] = Null
-
[Cost].Enabled = False
-
[Cost] = Null
-
[Comments].Enabled = True
-
Case "Interpretation"
-
[Date Provided].Enabled = True
-
[Providers].Enabled = True
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = True
-
[Comments].Enabled = True
-
Case "Translation"
-
[Date Provided].Enabled = True
-
[Providers].Enabled = True
-
[Number of Pages].Enabled = True
-
[Time].Enabled = True
-
[Comments].Enabled = True
-
Case Else
-
[Date Provided].Enabled = False
-
[Date Provided] = Null
-
[Providers].Enabled = False
-
[Providers] = Null
-
[Number of Pages].Enabled = False
-
[Number of Pages] = Null
-
[Time].Enabled = False
-
[Time] = Null
-
[Cost].Enabled = False
-
[Cost] = Null
-
[Comments].Enabled = True
-
End Select
-
End Sub
What confuses your post is your question: "What I would like to do, is make sure that whatever textboxes are enabled are also required. Is this possible?"
Based on your code, if you have run through enabling or disabling all of the available text boxes (based on the value of Outcome), then only those required text boxes would be enabled--unless there are some controls on your form that are not listed above.
But, it your really had to, you could query the Enabled Property of any other controls on your form.
As for some additional guidance and mentoring on building databases, it appears that your DB is in need of normalization. This may be a complete overhaul, but I would recommend it. You can find some guidance here: Database Normalization.
Additionally, with normalization, your combo box would not longer have text values, but numbers. Integers are a lot easier to work with, take up fewer resources, and it a standard in database development. In the long term, such changes will help you create robust and sound projects.
I cope the code above answered your question or at least hepped a bit.
Hello,
Thanks for the reply. Indeed I have a lot to learn. I just started teaching myself Access with this project mid May and have to have it complete by next Friday, so unfortunately, a complete overhaul is not gonna happen. However, I will definitely look at that link. I have been trying to read/watch as many tutorials as possible (even got a coding for dummies).
Good to know about the Select Case...indeed all the If...Then was getting annoying.
In regards to my question, I apologize it wasn't very clear. This is for my main form. The top half of the form has 9 controls that are always enabled and must be entered before the form can close. These fields are all set to required in the table. To get an idea, this form is for clients who wish to have an interpreter/translator provided to them and the top half is treated like an intake, where we enter the client information, the date they need the service, if they want an interpreter/translator, the language they want, etc. So when the case is first entered, the outcome will be "Pending" unless the service happened the same day as the request.
After the service is provided, we pull up the case again and change the "outcome" to interpretation or translation. Upon the outcome change, other controls become enabled, such as who provided the service, the date it actually was provided, the amount of time it took, the cost, etc. Once these fields are enabled, they should also be required before the form can be saved. However, right now, the form can be saved and closed even if they aren't filled out. I would like to prevent the users from just changing the "outcome" status (which would close the case) and not filling in the other fields.
I hope this clears up what I would like to do. Thanks!
Im a dunce and thought I had something going with the setproperty on the macro but I was wrong.
I thought I could try to use the Validation Rule, but it isn't working, so maybe I am doing it wrong.
I thought I could do: - If [Outcome]="Pending" OR [Outcome]="No Service" Then [Control]=Not Null
I also tried: - IIf([Outcome]="Pending" Or [Outcome]="No Service",[Providers]=Null,[Providers]=Not Null)
I also thought I could put in my code above, after each control is enabled to also have it =Not Null, but that didn't seem to work either.
Ok, I think I figured it out for the most part ;D - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Select Case Outcome
-
Case "Interpretation"
-
If IsNull(Me.[Date Provided]) Then
-
Cancel = True
-
MsgBox "Enter the date the service was provided!"
-
End If
-
If IsNull(Me.Providers) Then
-
Cancel = True
-
MsgBox "Enter a Provider!"
-
End If
-
If IsNull(Me.Time) Then
-
Cancel = True
-
MsgBox "Enter the time in minutes spent interpreting/translating"
-
End If
-
If [Providers] = "Outsider" And IsNull(Me.Cost) Then
-
Cancel = True
-
MsgBox "Enter the cost it took for service to be provided!"
-
End If
-
Case "Translation"
-
If IsNull(Me.Date_Provided) Then
-
Cancel = True
-
MsgBox "Enter the date the service was provided!"
-
End If
-
If IsNull(Me.Providers) Then
-
Cancel = True
-
MsgBox "Enter a Provider!"
-
End If
-
If IsNull(Me.Time) Then
-
Cancel = True
-
MsgBox "Enter the time in minutes spent interpreting/translating"
-
End If
-
If IsNull(Me.Number_of_Pages) Then
-
Cancel = True
-
MsgBox "Enter the number of pages that were translated!"
-
End If
-
If [Providers] = "Outsider" And IsNull(Me.Cost) Then
-
Cancel = True
-
MsgBox "Enter the cost it took for service to be provided!"
-
End If
-
Case "No Service"
-
If IsNull(Me.Comments) Then
-
Cancel = True
-
MsgBox "Enter a reason for why service was not provided!"
-
End If
-
End Select
-
End Sub
Only problem here is that it won't work for my combo box "Providers". I'm not sure why. It keeps popping up the message box after I select someone from the combo, and now it seems to have broken my code as it is still acting as if the code is there even after I deleted that portion of the code and restarted the program :(
Also, I am sure this doesn't look the best and could probably be written a different way, but it is what I figured out from multiple Google searches :D
Elaine,
Please explain the problem clearly. You say "the messagebox for Providers" but in fact, there are multiple references to the Providers combo box and each has a different message. So which message are you seeing?
Jim
Sorry, I meant the one with If IsNull([Providers]) Then...where the message states to enter a provider. I just saw something to try to add the Nz, so am going to try that.
Edit: This didn't work - If Nz(Me.Providers, "") = "" Then
-
Cancel = True
-
MsgBox "Enter a Provider!"
-
End If
Hmm, I pulled up a backup saved file and redid the code with the Nz and it works. So I don't know what happened to my other version but I think the problem of my combo is fixed. Thanks for the reply.
BTW, is there a way to mark this as solved?
So glad you got a good result. Congratulations. :)
There should be a link for you to mark the best answer.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mark |
last post by:
Access97 ---
I set the Required property for a field at the table level and I have a form
that contains that field. When I click the Close button at the top left of the
screen, I get an error...
|
by: Marcin Grzębski |
last post by:
Hi,
I want do create control (based on UserControl) that
contains collection MyItemCollection (inherited from ICollection)
of objects MyItem.
I spent so much time to force this collection save...
|
by: Kejpa |
last post by:
Hi,
I have a datatable which I try to update but the update fails because a
required property of one of the fields is set to True.
Where can I find this property?
On the Column there's only a...
|
by: Aaron Smith |
last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child
tables, I have a column that I added to the DataSet (Not in the
DataSource). This column does not need to be stored in the...
|
by: Just D. |
last post by:
All,
I created a tool to setup our web apps, it does almost everything now, but
how can we change the property of one of the subdirectories? One of the
subdirectories should be made Writeable.
...
|
by: Jim M |
last post by:
After learning that the 'subdatasheet name' property set to ""
can adversely effect database speed, I wanted to send a small code
snippent to my end users to reset the SubdatasheetName Property so...
|
by: Billy |
last post by:
Hopefully a simple one, what is the syntax to force a property to be required
in a user control?
I thought it would below, but it's not:
Public Required Property propName() As String
|
by: Randoz |
last post by:
I am trying to write an if/then statement to disable the "Required Property" and then to enable it after a record is saved. Almost like the visible and locked code.
|
by: shruthiKKKK |
last post by:
change appearence for textbox by using combolist
|
by: Andy Sauer |
last post by:
Hello. I have a database in Access 2002.
I have a table where the field "Name" is set as a required field.
I have a form that populates that table. When somebody forgets to fill in the Name...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |