Hi everyone,
total newbie to all of this so please bear with me and help if you can!
I'm creating a database for a charity using Access 2002 SP3, I have a form called "Member Data". Within the form I have two fields:
"Employed?" and "Employment Details".
"Employed?" is either Yes or No and is pulled from a table called Employed.EmployedDetail.
What I would like to happen is the "Employment Details" field on the form is greyed out, untill "Employed?" is set to Yes. If "Employed?" is set as No, then the box stays greyed out.
I've put No in Enabled under "Employment Details".
I've right-clicked on the field "Employed?", gone to Build Event > Code Builder in the Design View and entered this code: - Private Sub Employed_BeforeUpdate()
-
-
If Employed.[Employed Detail] = "Yes" Then
-
Employment Details.Visible = True
-
-
If Employed.[Employed Detail] = "No" Then
-
Employment Details.Visible = False
-
-
End Sub
This isn't working, but I know it should be something like this, if anyone can help me with this code then I would really appreciate it!
Many thanks,
Tony
14 6401
Hi everyone,
total newbie to all of this so please bear with me and help if you can!
I'm creating a database for a charity using Access 2002 SP3, I have a form called "Member Data". Within the form I have two fields:
"Employed?" and "Employment Details".
"Employed?" is either Yes or No and is pulled from a table called Employed.EmployedDetail.
What I would like to happen is the "Employment Details" field on the form is greyed out, untill "Employed?" is set to Yes. If "Employed?" is set as No, then the box stays greyed out.
I've put No in Enabled under "Employment Details".
I've right-clicked on the field "Employed?", gone to Build Event > Code Builder in the Design View and entered this code: Private Sub Employed_BeforeUpdate()
If Employed.[Employed Detail] = "Yes" Then
Employment Details.Visible = True
If Employed.[Employed Detail] = "No" Then
Employment Details.Visible = False
End Sub
This isn't working, but I know it should be something like this, if anyone can help me with this code then I would really appreciate it!
Many thanks,
Tony
You would need code in 2 places to accomplish what you want, In the AfterUpdate() Event of the Employment Field (chkEmployed), and in the Current() Event of the Form, place this same code. (Only the AfterUpdate() Event is shown). Hope this helps: - Private Sub chkEmployed_AfterUpdate()
-
If Me![chkEmployed] = True Then
-
Me![txtEmploymentDetails].BackColor = QBColor(15) 'White
-
Else
-
Me![txtEmploymentDetails].BackColor = RGB(128, 128, 128) 'Ugly Grey
-
End If
-
End Sub
Or alternatively: -
Private Sub chkEmployed_AfterUpdate()
-
If Me![chkEmployed] = True Then
-
Me![txtEmploymentDetails].Enabled = True
-
Else
-
Me![txtEmploymentDetails].Enabled= False
-
Me![txtEmploymentDetails]= ""
-
End If
-
End Sub
-
If you don't want them to be able to edit the field and to clear the field if they have selected "No".
Or alternatively: -
Private Sub chkEmployed_AfterUpdate()
-
If Me![chkEmployed] = True Then
-
Me![txtEmploymentDetails].Enabled = True
-
Else
-
Me![txtEmploymentDetails].Enabled= False
-
Me![txtEmploymentDetails]= ""
-
End If
-
End Sub
-
If you don't want them to be able to edit the field and to clear the field if they have selected "No".
Good point Rabbit!
NeoPa 32,511
Expert Mod 16PB
Good spot Rabbit.
I would tend to use the boolean fields a little differently myself : - Private Sub chkEmployed_AfterUpdate()
-
Me![txtEmploymentDetails].Enabled = Me![chkEmployed]
-
If Not Me![chkEmployed] Then Me![txtEmploymentDetails] = ""
-
End Sub
'And not forgetting... - Private Sub Form_OnCurrent()
-
Me![txtEmploymentDetails].Enabled = Me![chkEmployed]
-
If Not Me![chkEmployed] Then Me![txtEmploymentDetails] = ""
-
End Sub
Hi everyone,
many thanks for submitting code that should get this working, just another quick question:
Where EXACTLY do I need to put the two bits of code?
I told you I was a newbie!!
Thanks for your help,
Tony
If you go to the properties of the text box, click on the tab called Events. On there is where you will find the After Update Event. Click on the button with 3 dots and select Code Builder, that's where you enter the code.
You also want to put it in the Form's On Current Event. Same thing as the text box but you look at the properties of the form.
Hi everyone,
thanks for all your help on this, I've entered information as detailed here and it does work although I've found a small snag:
If Employed? is already on No, and you change it to Yes, then the code changes the Employment Details field to active so you can type something in - great!
BUT, if you then change the Employed? field back to No, then the Employment Details field stays active and does not grey out.
Ideally I need the Employment Details field to go back to grey if Employed? is changed.
Can anyone provide any further help with this?!
Many thanks,
Tony
NeoPa 32,511
Expert Mod 16PB
Can you post the code you're actually using.
I suspect you're not using the latest code I posted (post #5 - which should handle the situation you describe).
I would suggest using Rabbit's code in post #3 just with a few adjustments: -
Private Sub chkEmployed_Click()
-
If chkEmployed = True Then
-
txtEmploymentDetails.Enabled = True
-
Else
-
txtEmploymentDetails.Enabled = False
-
txtEmploymentDetails = ""
-
End If
-
chkEmployed.Requery
-
End Sub
-
change the AfterUpdate to Click,
get rid of the Me! bits
and add chkEmployed.requery to the end
its always worked fine for me in these situations, but in access 2000, im not sure if this makes a difference or not though
NDayave
NeoPa 32,511
Expert Mod 16PB
I'm not sure that going off at a tangent is a very good idea here. I appreciate the impulse to help, but from the code you posted, I'm not sure you've fully grasped the question as asked.
Again, I really don't want to sound critical or put you off from posting. Please feel free to contribute of your experience any time.
Tony, I think it would help all involved if you could post what you're currently using, to tie in with the problems you reported with the code in post #8.
Hi NeoPa & everyone,
thanks for your posts - I appreciate your help. The code I am using on the form is as follows:
Private Sub Form_OnCurrent()
Me![Employment Details].Enabled = Me![Employed?]
If Not Me![Employed?] Then Me![Employment Details] = ""
End Sub
Private Sub Employed__AfterUpdate()
Me![Employment Details].Enabled = Me![Employed?]
If Not Me![Employed?] Then Me![Employment Details] = ""
End Sub
I've changed the names slightly so they are consistent with the names I have in the DB.
The "Employment Details" field is greyed out all the time, and if you change the "Employed" field to either Yes or No, it will activate the greyed out "Employment Details" field. What I would like to happen is:
- "Employment Details" field is greyed out for starters
- If "Employed" is set to No, "Employment Details" stays greyed out
- If "Employed" is set to Yes, "Employment Details" becomes active
- If "Employed" is set back to No, "Employment Details" becomes greyed again
This must be a unique check for each record, as some people will be employed, and some won't so the query needs to check each record for the Yes/No parameter.
I hope I have explained myself clearly, and I hope you can help!
Once again, many thanks for your initial help and code, it is very much appreciated.
Regards,
Tony
NeoPa 32,511
Expert Mod 16PB
The "Employment Details" field is greyed out all the time, and if you change the "Employed" field to either Yes or No, it will activate the greyed out "Employment Details" field.
Tony, This bit is quite unclear. It seems to contradict itself.
Can you explain what is actually happening?
Can you confirm you are actually showing all this on a continuous form (this could be very important info)?
Just to clarify, I do understand what you're after and the code submitted should do that for you, but I'm not sure of the details when working on continuous forms - hence the questions.
Hi NeoPa,
I've checked on the Form properties and the default view is "Single Form". I can't change it to a Continuous Form as my current form contains several sub-forms.
The "Employment Details" code works exactly how I explained it:
1. Regardless of if the "Employed?" field is originally set as Yes or No, the "Employment Details" field is always greyed out
2. When you change the "Employed?" field to either Yes or No, the "Employment Details" field becomes active for all records.
Let me know if you need any more information and again, thanks for your help.
Tony
NeoPa 32,511
Expert Mod 16PB
1. Regardless of if the "Employed?" field is originally set as Yes or No, the "Employment Details" field is always greyed out
Does always mean it always starts out that way? If so, what does 'starts out' mean in this context? (When you change to a new record or when you open the form?)
2. When you change the "Employed?" field to either Yes or No, the "Employment Details" field becomes active for all records.
Again, does this mean that changing to another record, where the "Employed?" field has not been touched, still leaves the "Employment Details" field active, even when it shouldn't be.
Your code is is : - Private Sub Form_OnCurrent()
-
'Breakpoint the following line!
-
Me![Employment Details].Enabled = Me![Employed?]
-
If Not Me![Employed?] Then Me![Employment Details] = ""
-
End Sub
-
-
Private Sub Employed__AfterUpdate()
-
'Breakpoint the following line!
-
Me![Employment Details].Enabled = Me![Employed?]
-
If Not Me![Employed?] Then Me![Employment Details] = ""
-
End Sub
Breakpoint both indicated lines and trace through the code when you do your testing (Use Shift-F8 to progress through the code). Look for the values set when the code has passed the line.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ole S. Pedersen |
last post by:
I have two tables: eg. a person-table (no nulls allowed), with an id
and so on, and a person_course table (an intermediate table in a
many-to many relationship between person table and courses...
|
by: Wouter |
last post by:
Probably just a minor detail, because I almost got it working.
Creating the PDF file goes fine, thanks to all the bas****-files from
http://www.mvps.org/access/. Also the mail functionality goes...
|
by: Melissa |
last post by:
I have a frontend file named CustomerApp and backend file named CustomerData.
CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer
Database. Could someone help me with the code...
|
by: sheree |
last post by:
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2...
|
by: blindsey |
last post by:
Is there a tool that can take an Access database and generate SQL
"CREATE TABLE" statements for all the tables in it?
|
by: magmo |
last post by:
Hi
I have created a windows form that hold a datagrid, that datagrid gets
it values from a stored procedure. My problem is that I have added a
checkbox to the datagrid and applied some style...
|
by: EdB |
last post by:
In VB6, you could set a check box to checked, unchecked, or greyed. The
latter would be used to show a setting but disable the control.
In .Net, the third choice is not greyed, but...
|
by: Dave |
last post by:
I have multiple forms that will create an object. Basically a energy
efficiency measure object. The measure object will have a couple of
required properties set but after that it can have 10-20...
|
by: lxyone |
last post by:
Using a flat file containing table names, fields, values whats the
best way of creating html pages?
I want control over the html pages ie
1. layout
2. what data to show
3. what controls to...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |