Help with rudimentary Visual Basic 5.0 database connectivity

Help with rudimentary Visual Basic 5.0 database connectivity

Post by attor.. » Thu, 03 Apr 1997 04:00:00



I have an Access database (actually built with VB4 datamanager) with
one table, "Clients" and three fields: "ClientID" as a long integer,
"ClientLastName" and "ClientFirstName" as strings.  I have populated
the table with test data.

I've built a simple UserForm ("DataAccessTest") in Word's VBA just to
test database connectivity.  The form has three editboxes
"txtClientID", "txtClientLastName" and "txtClientFirstName".  It also
has four command buttons "cmdMoveFirst", "cmdMovePrevious",
"cmdMoveNext" and "cmdMoveLast".

I've got the following code:

Public Sub PopulateDialog()
    lngClientID = rs.Fields("ClientID").Value
    DataAccessTest.txtClientID.Text = Str(lngClientID)
    strClientLastName = rs.Fields("ClientLastName").Value
    DataAccessTest.txtClientLastName.Text = strClientLastName
    strClientFirstName = rs.Fields("ClientFirstName").Value
    DataAccessTest.txtClientFirstName.Text = strClientFirstName
End Sub

Private Sub cmdMoveFirst_Click()
    rs.MoveFirst
    Call PopulateDialog
End Sub

Private Sub cmdMoveLast_Click()
    rs.MoveLast
    Call PopulateDialog
End Sub

Private Sub cmdMoveNext_Click()
    rs.MoveNext
    If rs.EOF = True Then
        rs.MoveLast
    End If
    Call PopulateDialog
End Sub

Private Sub cmdMovePrevious_Click()
    rs.MovePrevious
    If rs.BOF = True Then
        rs.MoveFirst
    End If
    Call PopulateDialog
End Sub

Private Sub txtClientLastName_Change()

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
    Dim lngClientID As Long
    Dim strClientLastName As String
    Dim strClientFirstName As String
    Dim wrkSpace As Workspace
    Set wrkSpace = CreateWorkspace(Name:="", UserName:="admin",
Password:="", usetype:="dbUseJet")
    Dim db As Database
    Set db = wrkSpace.OpenDatabase(Name:="E:\Test DB.mdb")
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Clients", dbOpenDynaset)
    Set rs = db.OpenRecordset("Clients")
    Call PopulateDialog
End Sub

Any help would be greatly appreciated.

 
 
 

Help with rudimentary Visual Basic 5.0 database connectivity

Post by Dag Sund » Fri, 04 Apr 1997 04:00:00


What's the problem?

Dag.


Quote:> I have an Access database (actually built with VB4 datamanager) with
> one table, "Clients" and three fields: "ClientID" as a long integer,
> "ClientLastName" and "ClientFirstName" as strings.  I have populated
> the table with test data.

> I've built a simple UserForm ("DataAccessTest") in Word's VBA just to
> test database connectivity.  The form has three editboxes
> "txtClientID", "txtClientLastName" and "txtClientFirstName".  It also
> has four command buttons "cmdMoveFirst", "cmdMovePrevious",
> "cmdMoveNext" and "cmdMoveLast".

> I've got the following code:

> Public Sub PopulateDialog()
>     lngClientID = rs.Fields("ClientID").Value
>     DataAccessTest.txtClientID.Text = Str(lngClientID)
>     strClientLastName = rs.Fields("ClientLastName").Value
>     DataAccessTest.txtClientLastName.Text = strClientLastName
>     strClientFirstName = rs.Fields("ClientFirstName").Value
>     DataAccessTest.txtClientFirstName.Text = strClientFirstName
> End Sub

> Private Sub cmdMoveFirst_Click()
>     rs.MoveFirst
>     Call PopulateDialog
> End Sub

> Private Sub cmdMoveLast_Click()
>     rs.MoveLast
>     Call PopulateDialog
> End Sub

> Private Sub cmdMoveNext_Click()
>     rs.MoveNext
>     If rs.EOF = True Then
>         rs.MoveLast
>     End If
>     Call PopulateDialog
> End Sub

> Private Sub cmdMovePrevious_Click()
>     rs.MovePrevious
>     If rs.BOF = True Then
>         rs.MoveFirst
>     End If
>     Call PopulateDialog
> End Sub

> Private Sub txtClientLastName_Change()

> End Sub

> Private Sub UserForm_Click()

> End Sub

> Private Sub UserForm_Initialize()
>     Dim lngClientID As Long
>     Dim strClientLastName As String
>     Dim strClientFirstName As String
>     Dim wrkSpace As Workspace
>     Set wrkSpace = CreateWorkspace(Name:="", UserName:="admin",
> Password:="", usetype:="dbUseJet")
>     Dim db As Database
>     Set db = wrkSpace.OpenDatabase(Name:="E:\Test DB.mdb")
>     Dim rs As Recordset
>     Set rs = db.OpenRecordset("Clients", dbOpenDynaset)
>     Set rs = db.OpenRecordset("Clients")
>     Call PopulateDialog
> End Sub

> Any help would be greatly appreciated.