Sub Forms and Their controls

G

Guest

I have a main form with 3 sub forms on it each on different tabs. On the load
of the Parent form (frmaaMain) I have some fields on sub form (tblEnd) become
disabled. The code looks like this.

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

Me.Controls("tblEnd").Form.Controls("DateTime2").Enabled = False
Me.Controls("tblEnd").Form.Controls("Remarks2").Enabled = False
Me.Controls("tblEnd").Form.Controls("DateTime3").Enabled = False
Me.Controls("tblEnd").Form.Controls("Remarks3").Enabled = False
Me.Controls("tblEnd").Form.Controls("DateTime4").Enabled = False
Me.Controls("tblEnd").Form.Controls("Remarks4").Enabled = False

End Sub

I want the fields mentioned above to stay disabled until a certain event
happens. Example. On the AfterUpdate of Remarks1 text field If there is data
in the field that would unlock DateTime2 and Remarks2, and if there was data
in Remarks2 then DateTime3 and Remarks3 would open up. Following is the code
for that.

Option Compare Database
Option Explicit

Private Sub Remarks1_AfterUpdate()

If IsNull(Me.Remarks1) = False Or Me.Remarks1 <> " " Then
Me.Remarks2.Enabled = True And Me.DateTime2.Enabled = True
Else
Me.Remarks2.Enabled = False And Me.DateTime2.Enabled = False
End If

End Sub

I believe the code to be correct but it never works. I have also tried
..Visible and .Locked. Visible didn't work just like Enabled. Locked worked
but I would prefer to use Enabled. What do I have wrong in my code or do I
have a wrong option somewhere? Thanks in advance to anyone that contributes.

Michael
 
S

Sandra Daigle

I think the problem is that you have attempted to put multiple statements
into one line. This -

Me.Remarks2.Enabled = True And Me.DateTime2.Enabled = True

Should be two separate statements

Me.Remarks2.Enabled = True
Me.DateTime2.Enabled = True
 
G

Guest

Thank you Sandra!! Works like a charm. WOW that was an easy fix. I would
have never thought of to take the And out. Thanks a bunch

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top