Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using the ADODC control
Message
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00407044
Message ID:
00407077
Views:
25
>Hi,
>
>I'm a VFP programmer who's learning VB, so you'll have to bear with me.
>
>I'm using an ADODC control to navigate through a FoxPro table. The structure of the foxpro table is as follows:
>
>idfield INTEGER
>cname CHARACTER 60
>
>I have an ADODC control in my form, and the following code in the form:
>
>
>Private Sub Form_Load()
>    Dim rs As New ADODB.Recordset
>    rs.Open "Select * from customers", "DSN=ADOTest", adOpenKeyset, adLockPessimistic
>    Set Adodc1.Recordset = rs
>    Adodc1.Caption = "Customers"
>End Sub
>
>
>I have two textboxes in the form also, for the two fields. For field cname, I have set the MaxLength property of the texbox to 60 [the length of the field].
>
>This works great, except for the following: if I try to edit the character field, the textbox won't let me type anything unless I go to the end of the field and delete the trailing spaces. These spaces are not added by the user - they seem to be appended either by VB or the ODBC driver.
>
>I get around this by putting the following code in the gotfocus and lostfocus events of the textbox:
>
>Text3.Text = Trim(Text3.Text)
>
>If I am creating a data entry form in this way, would I have to put the above code in every textbox on the form ? In VFP for such a situation, I would put the code in my base textbox class, but I can't do that in VB.
>
>Also, instead of using Text3 to identify the textbox, is there some way of putting in generic code in the textbox [much the same as This in VFP] ?
>

VB will not support inheritance until version 7. You will have to put code in every textbox. But you can make your code generic if you use the Validate and Change events instead of Lost/GotFocus. Here is a simple example:
Private Sub Text3_Validate(Cancel As Boolean)
    ActiveControl.Text = TextValid(ActiveControl, Cancel)
End Sub

Public Function TextValid(oCtrl As TextBox, Cancel As Boolean) As String
    On Error GoTo INPUTERR
    ' do whatever validation here or simply:
    TextValid = Trim$(oCtrl.Text)
    Exit Function
    
INPUTERR:
    MsgBox "Invalid Input", vbExclamation
    Cancel = True
End Function
George
Previous
Reply
Map
View

Click here to load this message in the networking platform