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

Conditional enabling of controls

100+
P: 418
I created a form to enter expenses related to various grants for a given period. This form is called frmECHOEnter which is based on tblECHO. Selecting an ECHO number is required before entering expense data. I created a combo box cboEchoSelect for this purpose.

The form has a two-page sub forms (sfrmMTAP and sfrmSPAP). This two pages are placed using tab option. These are based on two different tables (tblMTAP and tblSPAP). I used the following SQL to make the sub form enabled once an ECHO number is selected and NOT before.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEchoSelect_AfterUpdate()
  2. Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.  
  5.     stDocName = "frmECHOEnter"
  6.  
  7.     stLinkCriteria = "[ECHOID]=" & Me![cboEchoSelect]
  8.  
  9.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  10.     EnableControls Me, acDetail, True
  11.     sfrmMTAP.Enabled = True
  12.     sfrmSPAP.Enabled = True
  13.  
  14.  
  15. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEchoSelect_DblClick(Cancel As Integer)
  2. On Error GoTo Err_cboEchoSelect_DblClick
  3.  
  4.     If IsNull(Me![cboEchoSelect]) Then
  5.         Me![cboEchoSelect].Text = ""
  6.     Else
  7.                 Me![cboEchoSelect] = Null
  8.     End If
  9.     DoCmd.OpenForm "frmECHO", , , , , acDialog, "GotoNew"
  10.     Me![cboEchoSelect].Requery
  11.  
  12.  
  13. Exit_cboEchoSelect_DblClick:
  14.     Exit Sub
  15.  
  16. Err_cboEchoSelect_DblClick:
  17.     MsgBox Err.Description
  18.     Resume Exit_cboEchoSelect_DblClick
  19. End Sub

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEchoSelect_NotInList(NewData As String, Response As Integer)
  2.     MsgBox "Double-click this field to add a New ECHO number to the list."
  3.     Response = acDataErrContinue
  4. End Sub
But the sub form remains enabled without having the end user selecting an ECHO number first. What is wrong with this SQL? I have similar form for another database and it works just fine. However, that form has a sub form that's just single page. Do I need to modify this because the sub form contains two pages?

Thanks for your help.
May 12 '09 #1
Share this Question
Share on Google+
5 Replies


Denburt
Expert 100+
P: 1,356
Hello M try adding the following:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  sfrmMTAP.Enabled = False
  3.   sfrmSPAP.Enabled = False
  4. End sub
You can adjust your after update function to read:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboEchoSelect_AfterUpdate()
  2.  Me.filter =  "[ECHOID]=" & Me![cboEchoSelect]
  3.  me.filteron=true
  4.      EnableControls Me, acDetail, True
  5.      sfrmMTAP.Enabled = True
  6.      sfrmSPAP.Enabled = True
  7.  
  8.  End Sub
May 12 '09 #2

100+
P: 418
Denburt:

It's working. Thanks a lot. M
May 12 '09 #3

Denburt
Expert 100+
P: 1,356
Glad I could help.
I am going to change the title for you so it might help others with similar issues.
May 12 '09 #4

100+
P: 418
Denburt:

That makes perfect sense. Thanks. Please see my new posting on primary key field being null.

I have a similar forms elsewhere and it works just fine. I don't understand why it would not work here.

Thanks.
May 12 '09 #5

NeoPa
Expert Mod 15k+
P: 31,709
A link (Error message on primary key field being null) would probably be helpful here ;)
May 12 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.