JohnDough185
Aug 1 2006, 08:09 AM
Hi,
I wanted to set a date field in my form to be visible if another field in the form is changed. Is that possible? The date field is defaulted as not visible so that the user can't see it unless they update another field. I feel like this should be a simple code that I could write under the OnChange property of the field that the user must update prior to the date field becoming visible. I don't know much about VB code, so any help would be much appreciated! Thanks
- John
freakazeud
Aug 1 2006, 08:12 AM
Hi,
I would just use the other controls after update event. If it is bound you can ensure that the value is different by using the oldvalue property e.g.:
If Me.YourControl <> Me.YourControl.OldValue Then
Me.YourOtherControl.Visible = True
Else
Me.YourOtherControl.Visible = False
End If
BTW...forms hold controls...fields are in tables.
HTH
Good luck
JohnDough185
Aug 1 2006, 08:39 AM
Thanks. I would think that that'd work too, but I'm having trouble getting it to work. Do I have to set the Visible property of the date control to Yes or No specifically? I'm updating the other control, but nothing's happening afterwards. Do I reference the controls by their Name or Control Source? How about using an ! instead of a . between "Me" and the control name? I've tried it all!!!
freakazeud
Aug 1 2006, 08:42 AM
You reference the controls by their name, a dot "." between me and the controlname is fine. If the evaluated control is bound then it should work.
If this is on the after update event of the control you first have to tab out of it for the code to be evaluated.
HTH
Good luck
JohnDough185
Aug 1 2006, 08:55 AM
I tried to make a new database and test it out, but now I'm getting an error that says that the method or data member is not found (referring to the .Visible part of the code). I'll post the database if you'd like to look @ it please? Thanks!
freakazeud
Aug 1 2006, 08:57 AM
You are not referencing the control name correctly and I think you were also missing an equal sign. It should be:
If Me.TestTableControl <> Me.TestTableControl.OldValue Then
Me.DateControl.Visible = True
Else
Me.DateControl.Visible = False
End If
HTH
Good luck
JohnDough185
Aug 1 2006, 09:04 AM
oops! Yup, it works. Now, when I go back to the other database, do everything the same, it's not doing anything after I tab out. No errors show up, but the after update event's not making my other control appear after it's updated! Is it because the control I'm referencing for the update is a combo box?
freakazeud
Aug 1 2006, 09:05 AM
That shouldn't matter. Just make sure you reference them all correctly. It is hard to see from over here what is missing.
HTH
Good luck
JohnDough185
Aug 1 2006, 09:23 AM
Here's the database. Hopefully you can find something, because it's killing me! Thank you so much for the help.
freakazeud
Aug 1 2006, 09:26 AM
Hi,
did you read up on normalization?
If not...I would strongly suggest you do so and correct your data model before you try to build forms/queries/reports...!
Some good reference posts (in no particular order) are:
HTH
Good luck
JohnDough185
Aug 1 2006, 02:21 PM
I figured out that the procedure is getting hung up on the fact that the field could be empty to start with. if that's the case, it messes up. Is there a way to get around that?
freakazeud
Aug 1 2006, 02:27 PM
You could add an evaluation for that e.g.:
If Not IsNull(Me.YourControl) Then
If Me.YourControl <> Me.YourControl.OldValue Then
Me.YourOtherControl.Visible = True
Else
Me.YourOtherControl.Visible = False
End If
End If
Eventhough a new value is still different then an old null value so the evaluation should have worked nevertheless. However, that still doesn't fix your structural problems!
HTH
Good luck
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.