Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,257 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,296 people online right now. Registration is fast and FREE... Join Now!




ado update problem

 
Reply to this topicStart new topic

ado update problem

el-sid
1 Dec, 2008 - 01:38 PM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 19


My Contributions
hi everyone, got a problem with my update to a database. the problem is i want to do an insert in two tables that are related using one command button. the first table- admin-updates, but the second one does not. it seems they cannot use the same connection
CODE

Dim cConn As ADODB.Connection
Dim rsAdmin As ADODB.Recordset
Dim Rx As Long, xCount As Integer
Private Sub EnableControls()
  Dim MyControl As Control
  For Each MyControl In Controls
    If TypeOf MyControl Is TextBox Then
      MyControl.Enabled = True
    End If
  Next
End Sub

Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub cmdsave_Click()
With rsAdmin
  
    .Open "select * from Admin", cConn, adOpenKeyset, adLockOptimistic
    .AddNew
    
    rsAdmin!Admin_no = txtadmin_no.Text
    rsAdmin!first_name = txtfirstname.Text
    rsAdmin!last_name = txtlastname.Text
    rsAdmin!department = txtdepartment.Text
            .Update
            .Requery
    MsgBox "Update Completed"
    .Close
End With

End Sub

Private Sub Form_Load()
frmadd.Show

  OpenConnection App.Path & "\ExamRegistration.mdb"
  
  'Call ClearControls
  Call DisableControls

Dim strEntry As Integer
strEntry = Val(InputBox("Enter the Administrator number"))

  rsAdmin.Open "select * from Admin where Admin_no=" & strEntry, cConn, adOpenKeyset, adLockOptimistic
  With rsAdmin
    If .BOF = True And .EOF = True Then
        Call ClearControls
        Call EnableControls
        txtadmin_no = strEntry
        txtfirstname.SetFocus
    Else
        txtadmin_no.Text = rsAdmin![Admin_no] & ""
        txtfirstname.Text = rsAdmin!first_name & ""
        txtlastname.Text = rsAdmin!last_name & ""
        txtdepartment.Text = rsAdmin!department & ""
        MsgBox "Record already exists"
        'Exit Sub
     End If
     .Close
   End With
End Sub
Private Sub ClearControls()
  Dim MyControl As Control
  For Each MyControl In Controls
    If TypeOf MyControl Is TextBox Then
      MyControl.Text = ""
    End If
  Next
End Sub
Private Sub DisableControls()
   Dim MyControl As Control
  For Each MyControl In Controls
    If TypeOf MyControl Is TextBox Then
      MyControl.Enabled = False
    End If
  Next
End Sub
Private Sub OpenConnection(strPath As String)
    ' Close on open connection
   If Not (cConn Is Nothing) Then
     cConn.Close
     Set cConn = Nothing
  End If

  'Create an instance of connection
  Set cConn = New ADODB.Connection

  'create an instance of recordset object
   Set rsAdmin = New ADODB.Recordset
  
  'set the cursor location
  cConn.CursorLocation = adUseClient
  ' Open a new connection
  cConn.Open "Provider=microsoft.jet.OLEDB.4.0;" _
   & "Data source= " & strPath
End Sub



please help

User is offlineProfile CardPM
+Quote Post


thava
RE: Ado Update Problem
2 Dec, 2008 - 02:58 PM
Post #2

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
My Contributions
where did you open the second table's record set seems there is no child table denoted here
User is offlineProfile CardPM
+Quote Post

el-sid
RE: Ado Update Problem
4 Dec, 2008 - 04:59 AM
Post #3

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 19


My Contributions
QUOTE(thava @ 2 Dec, 2008 - 02:58 PM) *

where did you open the second table's record set seems there is no child table denoted here

sorry i removed it before posting. the thing is i could not update 2 related tables because the connection seemed only dedicated to one result set. so what i was wondering is that is there a way to update both eg inserting a new member in a members table then inserting their username and password in a users table. those two tables are directly linked in that the members admin no is a row on the users table
User is offlineProfile CardPM
+Quote Post

thava
RE: Ado Update Problem
4 Dec, 2008 - 03:38 PM
Post #4

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
My Contributions
i can't under stand the salutation

but

u can update any table with different recordset and a single connection
if there is a primary and foreign key relation ship use the cascade update in the database side
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 11:04AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month