کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

لوپ در تمام کنترل های یک تب و تغییر رنگ کنترل فعال



فرم Single دارم با تب کنترل حاوی 15تب . تکست باکس و کمبوباکس های مختلفی در هر تب وجود دارد.فرم unbound است ( به جدولی وصل نیست ) . میخواهم از keypress در تب کنترل استفاده کنم تا در تمام کنترل های تمام تب ها حلقه ایجاد کند و رنگ پس زمینه را به سفید تغییر دهد روی تمام کنترل ها جزکنترل فعال ( فوکس گرفته ) که رنگ پس زمینه آن زرد شود.با Screen.ActiveControl می توانم مشخص کنم اما مطمئن نیستم چگونه اینرا در کدهایی بکار بگیرم تا لوپی بین هر کنترل بزنم.
I have a single form with a Tab Control containing 15 tabs. Various Text Boxes and Combo Boxes on each Tab. The Form is unbound. I want to use the KeyPress Event on the Tab Control to loop through all the controls on all tabs and change the background colour to white for all controls except the active control, where I want the background colour to be yellow. I can identify the Screen.ActiveControl but am not sure how to incorporate this into some code that loops through every control. Any bright ideas? Thanks for any help, as I'm new to this!
ایجاد حلقه در تمام کنترل های یک فرم : 


For Each Ctl In Me.Controls

If Ctl.ControlType=(acTextBox Or  acComboBox) Then

'DO SomeThing

Next

'If Ctl.ControlType=acTextBox Or Ctl.ControlType=acComboBox

لوپ در کنترلهای یک  سابفرم : 


در خط اول در کنترل های فرم می گردد چنانچه TypeName آن SubForm بود میرود به Form آن و تمام کنترل ها را در پنجره immidiate window محیط Vba نمایش میدهد ( Ctrl+G)


office/typename-function


For Each ctl In frm.Controls
    If TypeName(ctl) = "SubForm" Then
        Debug.Print ctl.Name & " is a SubForm"
        For Each ctlSub in ctl.Form.Controls
            Debug.Print ctlSub.Name
        Next 
    End If
Next


حال در جواب سوال بعد از ایجاد لوپ 

Ctl.BackColor = IIf(Ctl.Name = Screen.ActiveControl.Name, 8454143, 16777215)   

البته در کنترل تب ،  تب هایی وجود دارد و هر تب فقط یک پیج دارد رفرنس به تب خاص و پیج حاوی کنترل ها ( فرضا نام تب کنترل TabCtl0 باشد.)

iTabPage=0    پیج ایندکس تب اول صفر است

For Each Ctl In TabCtl0.Pages(iTabPage).Controls

'iTabPage=iif(iTabPage>15,0,iTabPage=iTabPage+1)



For i=0 To TabCtl0.Pages.Count -1    لوپ در پیج ها 



ControlType Property : 


acBoundObjectFrameBound object frame
acCheckBoxCheck box
acComboBoxCombo box
acCommandButtonCommand button
acCustomControlActiveX (custom) control
acImageImage
acLabelLabel
acLineLine
acListBoxList box
acObjectFrameUnbound object frame or chart
acOptionButtonOption button
acOptionGroupOption group
acPagePage
acPageBreakPage break
acRectangleRectangle
acSubformSubform/subreport
acTabCtlTab
acTextBoxText box
acToggleButtonToggle button


TypeName(Ctl)

Ctl.ControlType

If TypeOf Ctl is .....