• Lỗi hiển thị sai ngày trong SQL Server
  • Lỗi hiển thị sai ngày trong SQL Server

    tungthoi15 > 03-06-22, 09:19 AM

    => Vấn đề 1: 
    Em có link ODBC từ Access 2010 32bit tới SQL server, và có 1 đoạn code để cập nhật giá trị vào Filed: "Ngay" như sau

    Mã PHP:
    ....
    rs.Edit
    rs
    ("Ngay")= Format(Date(),"dd/MM/yy")
    rs.Update 


    Tuy nhiên, sau khi vào bảng kiểm tra lại thì nó lại hiển thị là: 22/05/30;
    Giá trị đúng và mong muốn phải là: 30/05/22

    => Vấn đề 2: 
    Khi em đóng 1 Form làm việc lại thì Forms Main nó lại bị co lại nhìn bé tý (không Maximum) được. Cho em hỏi mình sét thuộc tính như thế nào ạ? để cho lúc nào Form Main cũng Maximum
     
  • RE: Lỗi hiển thị sai ngày trong SQL Server

    ongke0711 > 03-06-22, 12:27 PM

    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 LongPtrByVal 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 LongPtrByVal X As LongByVal Y As LongByVal nWidth As LongByVal nHeight As LongByVal 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 LongPtrlpRect As Rect) As Long
        
    Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtrlpRect As Rect) As Long
    #Else
        Declare Function ShowWindow Lib "user32" (ByVal hWnd As LongByVal nCmdShow As Long) As Long
        
    Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
        
    Declare Function MoveWindow Lib "user32" (ByVal hWnd As LongByVal _
            X 
    As LongByVal Y As LongByVal nWidth As LongByVal nHeight _
            
    As LongByVal 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 maximizedrestore it.
            If IsZoomed(F.hWnd) <> 0 Then
                ShowWindow F
    .hWndSW_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.hWnd00MDIRect.x2 MDIRect.x1MDIRect.y2 MDIRect.y1True
        End Sub
        
        
        Sub MaximizeRestoredReport
    (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 
  • RE: Lỗi hiển thị sai ngày trong SQL Server

    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 LongPtrByVal 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 LongPtrByVal X As LongByVal Y As LongByVal nWidth As LongByVal nHeight As LongByVal 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 LongPtrlpRect As Rect) As Long
        
    Declare PtrSafe Function GetClientRect Lib "user32" (ByVal hWnd As LongPtrlpRect As Rect) As Long
    #Else
        Declare Function ShowWindow Lib "user32" (ByVal hWnd As LongByVal nCmdShow As Long) As Long
        
    Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
        
    Declare Function MoveWindow Lib "user32" (ByVal hWnd As LongByVal _
            X 
    As LongByVal Y As LongByVal nWidth As LongByVal nHeight _
            
    As LongByVal 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 maximizedrestore it.
            If IsZoomed(F.hWnd) <> 0 Then
                ShowWindow F
    .hWndSW_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.hWnd00MDIRect.x2 MDIRect.x1MDIRect.y2 MDIRect.y1True
        End Sub
        
        
        Sub MaximizeRestoredReport
    (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 

    Dạ, cám ơn anh, để em thử ạ