-
May 25th, 2011, 04:49 AM
#1
Thread Starter
New Member
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.
-
May 26th, 2011, 05:54 AM
#2
Member
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"
-
May 27th, 2011, 04:47 AM
#3
Thread Starter
New Member
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?
-
May 27th, 2011, 06:52 AM
#4
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|