• 0

VB6 [ how can I insert,update a record?


Question

I have 2 tables, I cant do it,,I always get an error could you please help?

here is the code.......I attached the source too

[/code]

Private Sub cmdClear_Click()

For Each ctl In Controls

If TypeOf ctl Is TextBox Then ctl.Text = ""

Next ctl

txtempno.SetFocus

End Sub

Private Sub cmdFind_Click()

'On Error GoTo ErrorMsg

DE1.rsemp.Open "select * from Employee" & _

" where empno = " & txtempno.Text & ""

If Not DE1.rsemp.BOF And Not DE1.rsemp.EOF Then

txtFirstName = DE1.rsemp("FirstName")

txtFamilyName = DE1.rsemp("FamilyName")

txtSalary.Text = DE1.rsemp("Salary")

txtHireDate.Text = DE1.rsemp("HireDate")

txtJob.Text = DE1.rsemp("Job")

txtCommission.Text = DE1.rsemp("Comm")

txtDeptNo.Text = DE1.rsemp("Deptno")

Else

MsgBox "Not Found", vbExclamation

End If

'ErrorMsg:

'MsgBox "Error 1"

'MsgBox Err.Description

DE1.rsemp.Close

End Sub

Private Sub cmdUpdate_Click()

On Error GoTo MsgErr

DE1.rsemp.Open " Select * From Employee " & _

" where empid = " & txtempno.Text & ""

If DE1.rsemp.RecordCount > 0 Then

UpdateRec

Else

End If

DE1.rsemp.Close

MsgErr:

MsgBox " Error 001"

MsgBox Err.Description

End Sub

Private Sub UpdateRec()

DE1.conn.Execute " Update Employee Set " & _

"Salary = " & txtSalary.Text

End Sub

Private Sub Command1_Click()

Dim rsemp As New ADODB.Recordset

If DE1.rslib.State <> adStateClose Then DE1.rslib.Close

DE1.rslib.Open "Select * From BooksIssue where empno = " & txtempno.Text & ""

Set H_Grid.DataSource = DE1.rslib

DE1.rslib.Close

End Sub

Private Sub PK()

'On Error GoTo Msg1

DE1.rslib.Open " select * from BooksIssue " & _

" where BookId = '" & txtPK.Text & "'"

If Not DE1.rslib.BOF And Not DE1.rslib.EOF Then

txtBookId.Text = DE1.rslib("BookId")

txtempno2.Text = DE1.rslib("Empno")

txtIssueDate.Text = DE1.rslib("IssueDate")

txtDueDate.Text = DE1.rslib("DueDate")

Else

MsgBox "Not avaiable,please choose from BookId column", vbExclamation

End If

'Msg1:

'MsgBox "Choose from BookId column please"

DE1.rslib.Close

End Sub

Private Sub Command2_Click()

DR1.Show

End Sub

Private Sub H_Grid_Click()

txtPK.Text = H_Grid.Text

PK

End Sub


code.zip

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Thats Easy. Where you have your error handling you need exit sub before it. Ive fixed it. Try that.

Private Sub cmdClear_Click()
For Each ctl In Controls
If TypeOf ctl Is TextBox Then ctl.Text = ""
Next ctl
txtempno.SetFocus
End Sub

Private Sub cmdFind_Click()
'On Error GoTo ErrorMsg
DE1.rsemp.Open "select * from Employee" &amp; _
" where empno = " &amp; txtempno.Text &amp; ""


If Not DE1.rsemp.BOF And Not DE1.rsemp.EOF Then

txtFirstName = DE1.rsemp("FirstName")
txtFamilyName = DE1.rsemp("FamilyName")
txtSalary.Text = DE1.rsemp("Salary")
txtHireDate.Text = DE1.rsemp("HireDate")
txtJob.Text = DE1.rsemp("Job")
txtCommission.Text = DE1.rsemp("Comm")
txtDeptNo.Text = DE1.rsemp("Deptno")

Else
MsgBox "Not Found", vbExclamation

End If

'ErrorMsg:
'MsgBox "Error 1"
'MsgBox Err.Description
DE1.rsemp.Close
End Sub

Private Sub cmdUpdate_Click()
On Error GoTo MsgErr
DE1.rsemp.Open " Select * From Employee " &amp; _
" where empid = " &amp; txtempno.Text &amp; ""

If DE1.rsemp.RecordCount &gt; 0 Then
UpdateRec
Else
End If


DE1.rsemp.Close


MsgErr:
MsgBox " Error 001"
MsgBox Err.Description


End Sub
Private Sub UpdateRec()
DE1.conn.Execute " Update Employee Set " &amp; _
"Salary = " &amp; txtSalary.Text




End Sub

Private Sub Command1_Click()

Dim rsemp As New ADODB.Recordset

If DE1.rslib.State &lt;&gt; adStateClose Then DE1.rslib.Close

DE1.rslib.Open "Select * From BooksIssue where empno = " &amp; txtempno.Text &amp; ""

Set H_Grid.DataSource = DE1.rslib
DE1.rslib.Close



End Sub

Private Sub PK()
'On Error GoTo Msg1

DE1.rslib.Open " select * from BooksIssue " &amp; _
" where BookId = '" &amp; txtPK.Text &amp; "'"
If Not DE1.rslib.BOF And Not DE1.rslib.EOF Then


txtBookId.Text = DE1.rslib("BookId")
txtempno2.Text = DE1.rslib("Empno")
txtIssueDate.Text = DE1.rslib("IssueDate")
txtDueDate.Text = DE1.rslib("DueDate")
Else
MsgBox "Not avaiable,please choose from BookId column", vbExclamation
End If
Exit Sub
'Msg1:
'MsgBox "Choose from BookId column please"
DE1.rslib.Close
End Sub

Private Sub Command2_Click()
DR1.Show
End Sub

Private Sub H_Grid_Click()
txtPK.Text = H_Grid.Text
PK
End Sub

Link to comment
Share on other sites

  • 0

no...did you take a look at the attached file?

I want to update and inser records through it into MS Access database file.

I get errors in the query...if someone could help me with ypdate insert queries please?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.