Vb database error

Sanchita Chakrabarty's Avatar
Light Poster
In relational database,eg: bank management i want to knw how to update the table in the deposit section, after a run time error is detected,if the account no: does not exist.In my case the control stops in that particular line. It does not go to the next line.So if u can please help me.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Use Ado object and not Ado control for better results. This just gives the hints as how to do it.

This code can give errors related to database and so Use more standard code. This is just an illustration of concept as to how to do it.

'Put 2 textbox, 1 command button and one ado controland connect to database
which has table name account with 2 fields accno and name where accno is primary 
key field.
Private Sub Command1_Click()
On Error GoTo ErrorHandler
If flag = False Then
'Change command button caption
	Command1.Caption = "Save"
'Insert the data and check if error occurs on primary key
	On Error GoTo DatabaseErrorHandler
	'Database error
	Adodc1.RecordSource = "Insert into account values(" + Text1.Text + ",'" + Text2.Text + "');"
	On Error GoTo ErrorHandler
	Command1.Caption = "Add"
End If
flag = Not flag
Exit Sub
'Change the value and insert
	Text1.Text = "3"
	Text2.Text = "New Name"
	Adodc1.RecordSource = "Insert into account values(" + Text1.Text + ",'" + Text2.Text + "');"
	MsgBox Err.Description, vbCritical + vbOKOnly
End Sub

Last edited by shabbir; 30Jul2004 at 17:11..