Results 1 to 4 of 4

Thread: VB6 Datagrid Column Formatting

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    10

    VB6 Datagrid Column Formatting

    Hi all, I would like to format a column in datagrid with 2 conditions. The column must be entered with only "N/A" or date (DD-MMM-YYYY) format value.
    Code:
    Private Sub cmdUpdate_Click()
      On Error GoTo UpdateErr
       
      If Me.grdDataGrid.DataFormats(10).Format <> "N/A" Then
      MsgBox "Invalid Data Entry!", vbInformation
      Exit Sub
      End If
      frmOutBOM.StatusBar1.Panels.Item(1).Text = "Saving Data ..."
      datPrimaryRS.Recordset.UpdateBatch adAffectAll
      Exit Sub
    UpdateErr:
      MsgBox Err.Description
    End Sub
    The code above still produce "Invalid Data Entry" message though N/A is the input when update button clicked. How to include both conditions? Please help anyone.

  2. #2
    Member
    Join Date
    Sep 2005
    Posts
    44

    Re: VB6 Datagrid Column Formatting

    What grid is this by the way as that might help us understand the problem more?

    There is a few ways to do this but looking at your code it looks incorrect. See below
    Code:
     'If the format is DD-MMM-YYYY" then your message will appear.  I would think you would want to check for both formats??
      If Me.grdDataGrid.DataFormats(10).Format <> "N/A" Then
         MsgBox "Invalid Data Entry!", vbInformation
         Exit Sub
      End If
    End Sub
    BUT, should you not be checking the value property instead of the format property? (Grid dependant)

    Code:
    Me.grdDataGrid.DataFormats(10).VALUE<> "N/A"

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    10

    Re: VB6 Datagrid Column Formatting

    Hi BAZIRELAND, thanks for the reply. I understand where I went wrong. I changed to below:
    Code:
    If Me.grdDataGrid.DataFormats(10).Value <> "N/A" Then
         MsgBox "Invalid Data Entry!", vbInformation
         Exit Sub
      End If
    End Sub
    How do we check date value?

  4. #4
    Member
    Join Date
    Sep 2005
    Posts
    44

    Re: VB6 Datagrid Column Formatting

    You can check for a date value using the IsDate function.
    Code:
    ISdate("01/043/2011") 'Returns false
    ISdate("01/04/2011") ' returns true
    You should have something similar to this
    Code:
    If Me.grdDataGrid.DataFormats(10).Value <> "N/A" _
       AND IsDate(Me.grdDataGrid.DataFormats(10).Value) = False _
       Then
         MsgBox "Invalid Data Entry!", vbInformation
         Exit Sub
      End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width