jo_2010 قام بنشر الثلاثاء at 11:15 قام بنشر الثلاثاء at 11:15 الخبراء الافاضل كيف اكتب قاعدة if مع الوقت اريد عمل الاتى عند فتح النموذج وكان الساعة بعد الثالثة عصرا يختفى زر اسمة Alborg كيف اكتب الدالة
تمت الإجابة Foksh قام بنشر الثلاثاء at 12:49 تمت الإجابة قام بنشر الثلاثاء at 12:49 وعليكم السلام ورحمة الله وبركاته .. اتمنى أن لا يكون هناك أمور لم تأت على ذكرها 😅😅 جرب في حدث عند التحميل لأي نموذج يحتوي الزر المطلوب ، الكود التالي Private Sub Form_Load() If Time() > #3:00:00 PM# Then Me.Alborg.Visible = False Else Me.Alborg.Visible = True End If End Sub 2
jo_2010 قام بنشر بالامس في 10:24 الكاتب قام بنشر بالامس في 10:24 21 ساعات مضت, Foksh said: وعليكم السلام ورحمة الله وبركاته .. اتمنى أن لا يكون هناك أمور لم تأت على ذكرها 😅😅 جرب في حدث عند التحميل لأي نموذج يحتوي الزر المطلوب ، الكود التالي Private Sub Form_Load() If Time() > #3:00:00 PM# Then Me.Alborg.Visible = False Else Me.Alborg.Visible = True End If End Sub خالص الشكر لحضرتك 1
ابو جودي قام بنشر منذ 4 ساعات قام بنشر منذ 4 ساعات في 17/6/2025 at 15:49, Foksh said: وعليكم السلام ورحمة الله وبركاته .. اتمنى أن لا يكون هناك أمور لم تأت على ذكرها 😅😅 جرب في حدث عند التحميل لأي نموذج يحتوي الزر المطلوب ، الكود التالي Private Sub Form_Load() If Time() > #3:00:00 PM# Then Me.Alborg.Visible = False Else Me.Alborg.Visible = True End If End Sub من باب النكاش مع اخى الحبيب @Foksh انا مبحبش اجاوب ع القد بالظبط لازم احط التاتش بتاعى ده كود ديناميكى علشان لو النموذج كان مفتوح اساسا قبل الوقت وطبعا لانى معقد باعمل حساب اى اخطاء وطبعا علشان موضوع ديناميكى ده يشتغل لازم ولابد وحتما : TimerInterval > 0 ' اسم التحكم المطلوب تغيير حالته Private Const strControlName As String = "Alborg" ' تفعيل الطباعة في نافذة Immediate لتتبع التنفيذ (يفضل تعريفه في وحدة عامة ) Public DebugMode As Boolean ' دالة تقوم بإرجاع الوقت الهدف بتنسيق موحد باستخدام TimeSerial Private Function GetTargetTime() As Date GetTargetTime = TimeSerial(15, 0, 0) ' الساعة 3:00:00 مساءً End Function ' التحقق مما إذا كان التحكم موجودًا في النموذج لتفادي الأخطاء Private Function ControlExists(ByVal strCtlName As String) As Boolean On Error Resume Next ControlExists = Not Me.Controls(strCtlName) Is Nothing On Error GoTo 0 End Function ' تحديث خاصية الظهور للتحكم حسب الوقت الحالي Private Sub UpdateControlVisibility() On Error GoTo Update_Error ' التأكد من وجود التحكم أولًا If ControlExists(strControlName) Then Dim bolShouldShow As Boolean bolShouldShow = (Time() <= GetTargetTime()) ' تغيير خاصية الظهور بناءً على الوقت Me.Controls(strControlName).Visible = bolShouldShow ' طباعة الحالة في نافذة Immediate إذا كان DebugMode مفعّل If DebugMode Then Debug.Print "Visibility of control '" & strControlName & "' set to: " & bolShouldShow & " at " & Now End If Else MsgBox "Control '" & strControlName & "' not found on the form.", vbExclamation, "Missing Control" End If Exit Sub Update_Error: MsgBox "An error occurred in UpdateControlVisibility: " & Err.Description, vbCritical, "Error" End Sub ' يتم استدعاء هذا الحدث عند تحميل النموذج لأول مرة Private Sub Form_Load() On Error GoTo Load_Error ' DebugMode = True ' تحديث حالة ظهور التحكم عند فتح النموذج UpdateControlVisibility Exit Sub Load_Error: MsgBox "An error occurred in Form_Load: " & Err.Description, vbCritical, "Error" End Sub ' يتم استدعاء هذا الحدث بشكل دوري إذا تم تفعيل Timer للنموذج Private Sub Form_Timer() ' تحديث حالة الظهور ديناميكيًا كل فترة UpdateControlVisibility End Sub 1
Foksh قام بنشر منذ 2 ساعات قام بنشر منذ 2 ساعات 18 دقائق مضت, ابو جودي said: انا مبحبش اجاوب ع القد بالظبط لازم احط التاتش بتاعى هههه ، انا لو كنت عاوز أفتح الباب للفضول أكتر ، كان اقترحت الفكرة دي مثلاً :- Private Sub Form_Load() On Error Resume Next Me.Alborg.Visible = (Time() <= #3:00:00 PM#) On Error GoTo 0 End Sub أما لو عاوز نفتحها بحري ونتوسع في الحديث ، فممكن نعمل الآتي :- في مديول لوحده كده بدون ما حد يزعجه :- Option Compare Database Option Explicit Public Enum ControlVisibility visible = 0 Hidden = 1 ErrorState = 2 End Enum Public Enum EventType Information = 0 Warning = 1 [Error] = 2 End Enum Public Function ShouldShowControl(Optional targetTime As Date = #3:00:00 PM#) As Boolean ShouldShowControl = (Time() < targetTime) End Function Public Function SetControlVisibility(frm As Form, ctlName As String, _ Optional targetTime As Date = #3:00:00 PM#) As ControlVisibility On Error GoTo ErrorHandler Dim ctl As Control Set ctl = frm.Controls(ctlName) If ctl Is Nothing Then SetControlVisibility = ErrorState Exit Function End If Dim visible As Boolean visible = ShouldShowControl(targetTime) ctl.visible = visible SetControlVisibility = IIf(visible, visible, Hidden) Exit Function ErrorHandler: LogEvent "Error setting visibility for " & ctlName, EventType.Error SetControlVisibility = ErrorState End Function Public Sub LogEvent(message As String, Optional msgType As EventType = EventType.Information) #If DEBUG_MODE Then Debug.Print Format(Now, "yyyy-mm-dd hh:mm:ss") & " [TimeBasedControl] " & _ Choose(msgType + 1, "INFO", "WARN", "ERR") & ": " & message #End If End Sub طبعاً هنقدر نستدعي الفكرة دي بشكل متعدد لأكثر من وقت وأكتر من هدف 😋 :- 1️⃣ الطريقة البسيطة الأولى :- Private Sub Form_Load() UpdateControlVisibility #7:00:00 PM# End Sub Private Sub Form_Timer() Static lastUpdate As Date If Now > lastUpdate + TimeSerial(0, 0, 30) Then UpdateControlVisibility #7:00:00 PM# 'هنا طبعاً الوقت اللي عايزه lastUpdate = Now End If End Sub Private Sub UpdateControlVisibility(targetTime As Date) Dim result As ControlVisibility result = SetControlVisibility(Me, "SendBtn1", targetTime) 'باللي انت عايزه SendBtn1 بدل اسم الزر If result = ErrorState Then MsgBox "فشل تحديث العنصر", vbExclamation + vbMsgBoxRight, "" End If End Sub 2️⃣ الطريقة الثانية :- Private mTargetTime As Date Private Sub Form_Load() mTargetTime = #8:45:00 PM# UpdateTimeDisplay UpdateControlVisibility End Sub Private Sub cmdSetTime_Click() Dim newTime As String newTime = InputBox("أدخل الوقت المطلوب (HH:MM:SS AM/PM)", "تعيين الوقت", Format(mTargetTime, "hh:mm:ss AM/PM")) If newTime <> "" Then If IsDate(newTime) Then mTargetTime = CDate(newTime) UpdateTimeDisplay UpdateControlVisibility Else MsgBox "تنسيق الوقت غير صالح", vbExclamation + vbMsgBoxRight, "خطأ" End If End If End Sub Private Sub UpdateTimeDisplay() lblCurrentTime.Caption = "الوقت الحالي: " & Format(Time, "hh:mm:ss AM/PM") & vbCrLf & _ "الوقت المستهدف: " & Format(mTargetTime, "hh:mm:ss AM/PM") End Sub Private Sub Form_Timer() Static lastUpdate As Date If Now > lastUpdate + TimeSerial(0, 0, 1) Then btnEvening.SetFocus UpdateTimeDisplay UpdateControlVisibility lastUpdate = Now End If End Sub Private Sub UpdateControlVisibility() Dim result As ControlVisibility result = SetControlVisibility(Me, "SendBtn1", mTargetTime) If result = ErrorState Then LogEvent "فشل تحديث عنصر التحكم", EventType.Error End If End Sub 3️⃣ الطريقة الثالثة ، وسأكتفي بدون ما نتوسع أكتر من كده 😅 :- Private Type ControlTimeSettings ControlName As String ShowBeforeTime As Date ShowAfterTime As Date End Type Private mControlSettings() As ControlTimeSettings Private Sub Form_Load() ReDim mControlSettings(2) With mControlSettings(0) .ControlName = "btnMorning" .ShowBeforeTime = #12:00:00 PM# .ShowAfterTime = #12:00:00 AM# End With With mControlSettings(1) .ControlName = "btnAfternoon" .ShowBeforeTime = #6:00:00 PM# .ShowAfterTime = #12:00:00 PM# End With With mControlSettings(2) .ControlName = "btnEvening" .ShowBeforeTime = #11:59:59 PM# .ShowAfterTime = #6:00:00 PM# End With UpdateControlsVisibility End Sub Private Sub Form_Timer() Static lastUpdate As Date If Now > lastUpdate + TimeSerial(0, 0, 30) Then UpdateControlsVisibility lastUpdate = Now End If End Sub Private Sub UpdateControlsVisibility() Dim i As Integer Dim currentTime As Date Dim shouldBeVisible As Boolean Dim result As ControlVisibility currentTime = Time() For i = LBound(mControlSettings) To UBound(mControlSettings) With mControlSettings(i) If .ShowAfterTime < .ShowBeforeTime Then shouldBeVisible = (currentTime >= .ShowAfterTime And currentTime < .ShowBeforeTime) Else shouldBeVisible = (currentTime >= .ShowAfterTime Or currentTime < .ShowBeforeTime) End If result = SetControlVisibility(Me, .ControlName, IIf(shouldBeVisible, #12:00:00 AM#, #11:59:59 PM#)) If result = ErrorState Then LogEvent "فشل تحديث عنصر التحكم: " & .ControlName, EventType.Error End If End With Next i End Sub Control Visibility.accdb 1
الردود الموصى بها
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.