VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Use Format/UnFormat events of Format Object in VB6

by Yuening Dai (30 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 25th October 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Use Format/UnFormat events of Format Object in VB6

Rate Use Format/UnFormat events of Format Object in VB6



'and prevent user from changing DB data (code in UnFormat event). 
'In the MS online help, I did not find any sample for UnFormat event of the 
'Format Object. This mini sample contains one one ADO data control and a TextBox
'on a form. The data will be from table "Products" with one field "ProductName"
'in an Access DB file. You need to create it and set the correct connection.
'Please set reference to MS Data Formatting Object Library and Data Binding
'Collection first.
'
Option Explicit
'Binds TextBox controls to the ADO control.
Dim bc As New BindingCollection
'
'We'll add code to Format/UnFormat events on this object.
Dim WithEvents fProduct As StdDataFormat        
Dim msOrigProductName As String 'For saved data.

Private Sub Form_Load()
  'Connect the BindingCollection object to the datasource.
  Set bc.DataSource = Adodc1
  '
  Set fProduct = New StdDataFormat
  'Binding TextBox to datasource, using format specified by fProduct.
  bc.Add txtProduct, "Text", "ProductName", fProduct, "product"
  '
End Sub

Private Sub fProduct_Format(ByVal DataValue As StdFormat.StdDataValue)
    '
    Debug.Print "Formated ProductName: " & DataValue.Value
    '
    'Save the original value of ProductName.
    msOrigProductName = DataValue.Value
    '
    'Change it to upper case and then sent to data-bound control.
    DataValue.Value = UCase(DataValue.Value)
    '
End Sub

Private Sub fProduct_UnFormat(ByVal DataValue As StdFormat.StdDataValue)
    '
    'Always write the saved data back to DB so that no data was changed.
    DataValue.Value = msOrigProductName
    '
End Sub



Download this snippet    Add to My Saved Code

Use Format/UnFormat events of Format Object in VB6 Comments

No comments have been posted about Use Format/UnFormat events of Format Object in VB6. Why not be the first to post a comment about Use Format/UnFormat events of Format Object in VB6.

Post your comment

Subject:
Message:
0/1000 characters