Disabling Fields from a Different Form/Table

moscgama

Registered User.
Local time
Today, 14:07
Joined
Feb 10, 2014
Messages
28
Hi,

I am trying to disable a field in a form based on a value in a field on a different table/form. I have been able, through simple VBA code, to disable fields based on a value in the same form. Is there VBA code to do this? If so, could you please give me an example? Or are queries/sub forms the only way to go? (Please be aware that I am not that familiar with VBA.)

Thanks in advance for the help!
 
Hi pbaldy,

Thanks for your reply! I tried referencing the other form in the following code:

Private Sub ID_AfterUpdate()

DoCmd.OpenForm "Culture_PFGE_Form", acNormal, , , , acHidden

If Forms!Culture_PFGE_Form!culture_interp = "1" Then
Me.mlst_date.Enabled = True

Else: Me.mlst_date.Enabled = False


End If

End Sub

Using this code, the mlst_date field is disabled, no matter the value of culture_interp. The tables on which the forms are based are linked by ID. I added the code to after ID update, since this piece of information is needed to link the tables. Also, the culture_interp is a combo box. Please let me know if more information is needed!

Any suggestions are much appreciated!
 
Does dropping the quotes work?

If Forms!Culture_PFGE_Form!culture_interp = 1 Then

or the whole code using Boolean logic:

Me.mlst_date.Enabled = (Forms!Culture_PFGE_Form!culture_interp = 1)
 
Hi pbaldy,

Thanks again for your help and I apologize for the delay in my response! I tried both of your suggested methods. I still have the same problem when removing the quotation marks. For your second suggestion, the Boolean code, when I run the code I receive a Run Time 94 error. I tried solving this error by adding a Dim set as string/variant, but neither worked.

Do you happen to have further suggestions?
 
Can you post the db here to test on? My only thought is adding

DoEvents

after opening the form, in case it takes too long to open.
 
Hi pbaldy,

Unfortunately, I don't feel comfortable uploading the database, but I will look at DoEvents and play around with the code a bit more. I really appreciate your help!

All the best!
 

Users who are viewing this thread

Back
Top Bottom