monurenjith 0 Newbie Poster

i hav two tables - loan application and loanguarantee
i ' ve written two subroutines in a btn click event to insert values into the two tables . the situation is that- a single loan applicant may have more than two guaranteers which is in the loan guarantee table. i inserted the applicant details and after that id in that table is taken which is given as auto increment and primary key . based on this key next insertion is made using a for loop into the loan guarantee table. no errors are shown . but after the insertion when i look into the database there is only one set of values inserted- either loanapplication or loanguarantee. what's the problem pls help me......... this is my code........

Private Sub cmdSave_Click()
insertintoLoanApplication
insertintoLoanGuarantee

End Sub
Private Sub insertintoLoanGuarantee()
Dim i, intLoanid As Integer

CCdbconnection
Set myrs = New ADODB.Recordset
myrs.Open " SELECT max(id) FROM loanapplication ", mydatabase
intLoanid = myrs.Fields(0)
Set myrs = Nothing
Closedb

CCdbconnection
For i = 1 To intRows

mydatabase.Execute "INSERT INTO loanguarantee(loanid,acno) values(" & intLoanid & ", '" & msfGrt.TextMatrix(i, 1) & "')"
' mydatabase.Cancel
MsgBox "inserted inot loan guarantee table........", vbInformation
Next i
Closedb

End Sub

Private Sub insertintoLoanApplication()
Dim sam As ADODB.Recordset
Set sam = New ADODB.Recordset

'insert data into the LoanApplication table...............................
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------
CCdbconnection
On Error GoTo inserterror
mydatabase.Execute "INSERT INTO loanapplication(acno,need,loanamt,reference,apprmtng,assignedlonamt, status,appldate,sancdate) values('" & cmbAcid.Text & "', '" & txtneed.Text & "'," & CDbl(txtloanamt.Text) & ",'" & txtReference.Text & "','" & txtdetsAprmtg.Text & "'," & CDbl(txtAssignAmt.Text) & ", 'o' , '" & CStr(dtpDate.Value) & "' , '" & CStr(dtpDate.Value) & "')"
mydatabase.Cancel
MsgBox "Inserted Loan Application table.......", vbInformation
inserterror:
' MsgBox Err.Description
'----------------------------------------------------------------------------------------------------------------------
Closedb
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.