tungthoi15 > 03-06-22, 09:19 AM
....
rs.Edit
rs("Ngay")= Format(Date(),"dd/MM/yy")
rs.Update
ongke0711 > 03-06-22, 12:27 PM
Private Sub Form_Open()
MaximizeRestoreForm Me
End Sub
Option Compare Database
Option Explicit
Public Type Var64
#If VBA7 And Win64 Then
Long As LongPtr
#ElseIf VBA7 Then
Long As LongPtr
#Else
Long As Long
#End If
End Type
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
#If VBA7 Then
Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function IsZoomed Lib "user32" (ByVal hWnd As LongPtr) As Long
Declare PtrSafe Function MoveWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare PtrSafe Function GetParent Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As Rect) As Long
Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As Rect) As Long
#Else
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal _
X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
'Use following instead of GetWindowRect
Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect _
As Rect) As Long
#End If
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Sub MaximizeRestoredForm(F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(F.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub
Sub MaximizeRestoredReport(r As Report)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(r.hWnd) <> 0 Then
ShowWindow r.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(r.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow r.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub
tungthoi15 > 03-06-22, 03:19 PM
(03-06-22, 12:27 PM)ongke0711 Đã viết: 1. Đối với trường Ngày tháng trong VBA, bạn cứ để y nguyên vậy mà Update, Format làm chi cho mất công, khi nào muốn hiển thị thì mới dùng Format() để xem cho đúng ý đồ. Mỗi máy có thiết lập ngày tháng khác nhau trong Control Panel, do đó người dùng cứ nhập liệu đúng kiểu đã thiết lập trong hệ thống là nó sẽ chính xác hơn can thiệp bằng Format.
2. Form bị thu nhỏ là do tính năng Restore mặc định của nó. Bạn dùng hàm dưới đây để thay thế Docmd.Maximize
Mã PHP:Private Sub Form_Open()
MaximizeRestoreForm Me
End Sub
Mã PHP:Option Compare Database
Option Explicit
Public Type Var64
#If VBA7 And Win64 Then
Long As LongPtr
#ElseIf VBA7 Then
Long As LongPtr
#Else
Long As Long
#End If
End Type
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
#If VBA7 Then
Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function IsZoomed Lib "user32" (ByVal hWnd As LongPtr) As Long
Declare PtrSafe Function MoveWindow Lib "user32" (ByVal hWnd As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare PtrSafe Function GetParent Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As Rect) As Long
Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtr, lpRect As Rect) As Long
#Else
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal _
X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
'Use following instead of GetWindowRect
Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect _
As Rect) As Long
#End If
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Sub MaximizeRestoredForm(F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(F.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub
Sub MaximizeRestoredReport(r As Report)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(r.hWnd) <> 0 Then
ShowWindow r.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
GetClientRect GetParent(r.hWnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
MoveWindow r.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
End Sub