By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,087 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Disabling part of a form on startup and setting the focus

P: n/a
I borrowed one of the forms from the MS Access Solutions database and
altered it to fit my needs. The form was the 'EditProducts' form where you
select a category from a combo which then populates another combo for
products. Then when you select a product, the form displays the info for it.
Everything is working well except, with the original, when the form is
opened, the focus is on the SelectCategory combo box, while the form
elements are greyed out until you select a category and product. When I open
my form, the main form is active, and the focus is on one of those controls.
Once I select an item from the first combo box in the header, then the form
controls grey out until I select a option from the second combo. I am at my
wits end trying to figure out what I've missed. I've posed the code for the
form below.

Option Compare Database
Option Explicit

Private Sub Form_AfterUpdate()

' Requery SelectProduct combo box.
Me!SelectProject.Requery
End Sub

Private Sub SelectClient_AfterUpdate()

' Enable and requery SelectProduct combo box.
' Disable controls in detail section.

Me!SelectProject.Enabled = True
Me!SelectProject.Requery
EnableControls Me, acDetail, False
End Sub

Private Sub SelectProject_AfterUpdate()

' Find record for product selected in SelectProduct combo box.
' Enable controls in detail section and disable ProductID text box.
' Go to SupplierID combo box.

DoCmd.ApplyFilter , "ProjectID = Forms!frmWorksheet!SelectProject"
EnableControls Me, acDetail, True
Me!ProjectID.Enabled = False
Me!ProjectLocation.SetFocus
End Sub

Private Sub SelectProject_BeforeUpdate(Cancel As Integer)
If IsNull([SelectProject]) Then
MsgBox "You must select a project."
Cancel = True
End If

End Sub
May 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In the Load event procedure of the form, SetFocus to the combo, and call the
code tha disables the contorls in the Detail section:
Me.SelectProject.SetFocus
EnableControls Me, acDetail, False

We don't know what the EnableControls sub does, but that should work if the
SelectProject combo is not in the Detail section.

(If the form returns no records, and no new records can be added, Access
could have problems.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Robert" <no**@email.com> wrote in message
news:Pm*******************@fe01.news.easynews.com. ..
I borrowed one of the forms from the MS Access Solutions database and
altered it to fit my needs. The form was the 'EditProducts' form where you
select a category from a combo which then populates another combo for
products. Then when you select a product, the form displays the info for
it. Everything is working well except, with the original, when the form is
opened, the focus is on the SelectCategory combo box, while the form
elements are greyed out until you select a category and product. When I
open my form, the main form is active, and the focus is on one of those
controls. Once I select an item from the first combo box in the header,
then the form controls grey out until I select a option from the second
combo. I am at my wits end trying to figure out what I've missed. I've
posed the code for the form below.

Option Compare Database
Option Explicit

Private Sub Form_AfterUpdate()

' Requery SelectProduct combo box.
Me!SelectProject.Requery
End Sub

Private Sub SelectClient_AfterUpdate()

' Enable and requery SelectProduct combo box.
' Disable controls in detail section.

Me!SelectProject.Enabled = True
Me!SelectProject.Requery
EnableControls Me, acDetail, False
End Sub

Private Sub SelectProject_AfterUpdate()

' Find record for product selected in SelectProduct combo box.
' Enable controls in detail section and disable ProductID text box.
' Go to SupplierID combo box.

DoCmd.ApplyFilter , "ProjectID = Forms!frmWorksheet!SelectProject"
EnableControls Me, acDetail, True
Me!ProjectID.Enabled = False
Me!ProjectLocation.SetFocus
End Sub

Private Sub SelectProject_BeforeUpdate(Cancel As Integer)
If IsNull([SelectProject]) Then
MsgBox "You must select a project."
Cancel = True
End If

End Sub

May 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.