i am trying to develop a database management software.using MS ACCESS 2003 as back-end and VISUAL BASIC 6.0 as front end.. i am having a problem..can any one help with this..
i have typed the code below in a module for the connection to the database...and connection to the record set
Public SQL As String
Public connPukoo As ADODB.Connection
Public CustomerInfo As ADODB.Recordset
Public Sub dbconnection()
'connection to the database
Set connPukoo = New ADODB.Connection
connPukoo.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Pukoo.mdb;Persist Security Info=False"
connPukoo.CursorLocation = adUseClient
connPukoo.Open
'database connection established
End Sub
Public Sub connrecordset(tbname As ADODB.Recordset, sequel As String)
'connect to record set
Set tbname = New ADODB.Recordset
With tbname
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = sequel
.ActiveConnection = connPukoo
.Open
End With
'connection to the record set established
End Sub
and the code below in the form's code editor window to add entries into the database.
Private Sub Command1_Click()
SQL = "select * from cusinfo"
Call connrecordset(CustomerInfo, SQL)
CustomerInfo.MoveLast
With CustomerInfo
CustomerInfo.MoveLast
!Name = txtName.Text
!Address = txtAddress.Text
!DOB = DTDOB.Value
!Age = DateDiff("yyyy", DTDOB.Value, Now()) + Int(Format(Now(), "mmdd") < Format(DTDOB.Value, "mmdd"))
!Sex = cmbSex.Text
!PassportNo = txtPassport.Text
!Country = txtCountry.Text
!City = txtCity.Text
!TelephoneNo = txtHome.Text
!MobileNo = txtMobile.Text
!Email = txtEmail.Text
.Update
End With
End Sub
code below shows ,calling for the connection when form loads up
Private Sub Form_Load()
Call dbconnection
End Sub
the problem is it sometimes it add entries into the data base and sumtimes it throws the following error.
Run-time error '-2147217887 (80040e21)':
Multiple- step operation generated errors. Check each status value.
and when i press debug it goes to the command button1 click events line indicated below
!TelephoneNo = txtHome.Text