Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Control On change event does not execute code to disable textbox 1

Status
Not open for further replies.

polnichek

Technical User
Dec 13, 2005
35
0
0
CA
I have a Main Form called frmPurchaseRequest that has a tab control (TabCtl0) on it with three tabs. Each tab uses the same sub form to capture data entry (context oriented each tab represents a different way of acquiring goods and services). the intention is to have a client click on a tab and the sub form would display different text boxes and controls depending on the tab opened. Unfortunately I cant get the ON Change event to enable or disable the controls properly. At the moment if you click on the desired tab in this case HC1000 Purchase Request (pagHc1000) it does nothing, but when you click on the previous tab LPO-CreditCard (pagLPO) (it disables the textbox (txtPO_Number) I wanted it to disable when you click on HC1000 Purchase Request.

'Code to execute:
Private Sub TabCtl0_Change()

Dim intCtrlVal As Integer
intCtrlVal = Me.TabCtl0.Value


'intCtrlVal = 3
Select Case intCtrlVal
Case 0
'code to execute if LPO-Credit (pagLPO) Card is selected
'this executes properly
MsgBox " you have selected LPO Credit Card"


Case 1

MsgBox " you have HC 1000 Purchase Request"
'code to execute if HC1000 (pagHc1000) is selected

'below does not in the app this code is all one line
Forms![frmPurchaseRequest]! [frmPurchReq_Sub].Form!txtPO_Number.Enabled = False

Case 2

'executes properly
MsgBox " you have selected CFA"
'code to execute if CFA is selected

Case Else
MsgBox "There has been an error!"

End Select

End Sub

'End of code to execute

I can post the database file if necessary


Polnichek
 
How are ya polnichek . . .

Are you saying you have the same subform on all three tabs?

If so ... are you saying they all have the same name (frmPurchReq_Sub)? ... say this isn't so!

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi TheAceMan1!

thanks for your reply,

Yes you are correct all thrre tabls would have the same sub form name (frmPurchReq_Sub)

the three different data entry screens have almost identical data to be entered depending on the three different ways the Purchase Department can buy goods and services. They only have minor differences between the various processes.

If there is a better way to do this I would gladly explore that, the tab control structure seems glitchy and not very intuitive to write code for!

I forgot to mention I am using Access 2003.

polnichek

Polnichek
 
Code:
'Code to execute:
Private Sub TabCtl0_Change()  
   dim frm1 as access.form
   dim frm2 as access.form
   dim frm3 as acess.form
   Dim intCtrlVal As Integer
   
  'if you have three sub forms on different tabs
  'then each subform has its own subform control.
  'I will put in notional names
   set frm1 = Forms![frmPurchaseRequest]![frmPurchReq_Sub].Form
   set frm2 = Forms![frmPurchaseRequest]![frmPurchReq_Sub2].Form
   set frm3 = Forms![frmPurchaseRequest]![frmPurchReq_Sub3].Form
  
  intCtrlVal = Me.TabCtl0.Value
  
  'intCtrlVal = 3
   Select Case intCtrlVal
      Case 0
        'code to execute if LPO-Credit (pagLPO) Card is selected
        'this executes properly
        MsgBox " you have selected LPO Credit Card" 
        'I assume you want to modify form 1
        with frm1
          .somecontrol.enabled = false
          .someothercontrol = ...
        end with
      Case 1
        MsgBox " you have HC 1000 Purchase Request"
        'code to execute if HC1000 (pagHc1000) is selected
        with frm2
          .somecontrol.enabled = false
          .someothercontrol = ...
        end with
      Case 2
         'executes properly
         MsgBox " you have selected CFA"
         'code to execute if CFA is selected
         'I assume you want to modify form 3
        with frm3
          .somecontrol.enabled = false
          .someothercontrol = ...
        end with
      Case Else
         MsgBox "There has been an error!"
     End Select
End Sub

'End of code to execute

However, you do not need three subforms. Just drag the subform onto the tab control, but do not paste it into a page. Basically it sits on top of the tab control instead of being embedded into a tab. It will then appear as if it is on every page.
 
thank you again,

I did as you suggested....I misunderstood what you had said initially about having three sub forms with the same name. I did have only one instance of the sub form but I had wondered if perhaps the tab control may have interpreted it as having three instances of a single form open at the same time...Having said that I may have used copy and paste to put the sub on the tab control so I deleted it and used drag and drop as you suggested... Unfortunately I have the same result as before, I only get the desired text box to disable when I click on the previous tab and not the intended tab.

I know the case structure is firing properly because I inserted a message boxes at the decision points to interrupt code execution and this works like I want it too.

your help is greatly appreciated!

polnichek

Polnichek
 
thanks MajP,

I will give your suggestions a try tomorrow (have to run right now!) and let you know. I reviewed some of the adjustments you made to my basic structure and they make sense.

Polnichek
 
Based on your last post, I doubt my changes would effect anything. Sounds like you have something else going on. My changes were really to simplify if you had 3 subform instances of the same form.
 
polnichek . . .

Perhaps you can upload to [link 4shared.com]4Shared[/url] (its free) ...

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi MajP

so right, your suggestion is not going to help unfortunately..I am beginning to hate the tab control structure...

David



Polnichek
 
TheAceMan1
I can upload but I have to clean it first, I work for governement and I cant send out anything I want to!

I will try and send up a version that security will be happy with by tomorrow.

Polnichek




Polnichek
 
I do not think the issue is with the tab control. It sounds and looks like you are using it correctly. My guess is there is a simple logic error that you are not seeing or a timing error.

So if the only problems is that this line is not executing

Forms![frmPurchaseRequest]! [frmPurchReq_Sub].Form!txtPO_Number.Enabled = False

try a couple of things to debug
1) Make sure it is not a logic error. Double check the name of the control.

2) add some debugging
Forms![frmPurchaseRequest]! [frmPurchReq_Sub].Form!txtPO_Number.Enabled = False
'add
msgbox Forms![frmPurchaseRequest]! [frmPurchReq_Sub].Form!txtPO_Number.Enabled
'should return false
'add doevents here maybe there is a timing problem
doEvents
 
Hi MajP

thank you again for your post. I like your debugging ideas and I will use them in future.

Well....there was another possibility...I call them SAT's...short for Stupid Access Tricks.

I exported the contents of the application to a new database container (.mdb file) and it works fine.

I do not understand why since I did not change any code.

Thank you every one for posting, this problem has been solved.

Polnichek
 
I may have spoken too soon. the demon is back and I am not sure why...I will update with more information soon.

Polnichek
 
I have done some further testing on this problem and it seems I can refer to the 'Value' of the text box and successfully update it with a new value, but as soon as I try to change a property, in this case disable the textbox nothing happens, or I get an inconsistent result as described above.



Polnichek
 
did you try adding doevents. There may be a timing issue.
 
polnichek said:
[blue]Each tab uses the same sub form to capture data entry ([purple]context oriented each tab represents a different way of acquiring goods and services[/purple]).[/blue]
Could you explain [blue]how your accomplishing this[/blue] and what the user sees ...

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you MajP for your comments and suggestions, I did add DoEvents as you suggested, (I copied and pasted your code into my Case Statement) and it did indeed return False. I amy be a bit dense on event based programming because I am not sure how it helps...

TheAceMan1. Thanks for your question, I basically put a tab control on a form and then put the sub form on the the first Tab using Drag and Drop, then I clicked on the second tab and used drag and drop again. I created a third tab and I do intend to use drag and drop but I was hoping to get the first two working.... I can perhaps send you two screen shots of the data entry screens?


I would like to upload the database for your review but unfortunately I have to wait until my security department approves its release.

Thank you both for your help so far, I have not been programming for a while, and I have never used a tab control structure before so I am stumped.

Polnichek



Polnichek
 
Some info
Each time the form handles an event, it processes all the code associated with that event. All other events wait in the queue. While your code handles the event, your application does not respond. For example, the window does not repaint if another window is dragged on top.

If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing.
 
polnichek said:
[blue] ... I have never used a tab control structure before so I am stumped.[/blue]
A Tab control is simply a display object. You reference the subforms and other controls as if it were'nt there.

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi there,

hope everyone had a good weekend!

for both MajP and TheAceMan1
I was able to get permission to post a cleaned up version of the system, it has very limited test data in the system so hopefully it will not be an impediment to figuring this out

TheAceMan1
I am glad you said reference the subforms as if the tab control is not there, that is what I have been trying to do, and as you will see I get inconsistent results.

When clicking on HC1000 Purchase Request tab (using the On change event of the Tab Control) I should get:

Expected: The same sub form but with PO Number disabled
Result: The same sub form but nothing happens

If i Click on the tab LPO-Credit Card

Expected: The PO Number text box should be come enabled
Result: the PO Number text box becomes disabled and then enabled!

This does lead me to suspect MajP is correct that it is some kind of timing issue but since I do not have a good enough understanding of how this works in Access I am not able to figure it out.




Polnichek
 
 http://www.4shared.com/folder/uUh4xJP0/_online.html
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top