I have 4 tables in SQL 2000. I linked them in MS ACCESS 2003. One of the table is parent table havinf personal information. The other table stores Licenses. One person can have multiple license.
I created a query which joins both Parent and Child tables. In a datasheet view of this query if I add any record it will populate both the child and parent. This works fine.
I created a form which is bound to this query. I have two commands on this form. Add new record and Save record. I am posting code at the end.
When I click on add record it will clear all the fields and allow me to enter data. When I click on "Save Record", it takes some time and says "ODBC call failed"
Please help me with this.
I created a query which joins both Parent and Child tables. In a datasheet view of this query if I add any record it will populate both the child and parent. This works fine.
I created a form which is bound to this query. I have two commands on this form. Add new record and Save record. I am posting code at the end.
When I click on add record it will clear all the fields and allow me to enter data. When I click on "Save Record", it takes some time and says "ODBC call failed"
Please help me with this.
Code:
Option Compare Database
Dim str As String
Dim namecode As String
Private Sub cmdsave_Click()
On Error GoTo Err_cmdsave_Click
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "Query3", CurrentProject.Connection
If rst.Supports(adAddNew) Then
With rst
.AddNew
.Fields("NAME_CODE") = namecode
namecode = txtltype & txtlname & Left(Me.txtfirstname, 1) & txtmi
Debug.Print namecode
.Fields("LAST_NAME") = txtlname
.Fields("FIRST_NAME") = txtfirstname
.Fields("MIDDLE_INITIAL") = txtmi
.Fields("Suffix") = txtsuffix
.Fields("SSN") = txtssn
.Fields("ADDRESS") = txtaddress1
.Fields("ADDRESS2") = txtaddress2
.Fields("CITY") = txtcity
.Fields("STATE") = txtstate
.Fields("ZIP_CODE") = txtzipcode
.Fields("COUNTY") = txtcounty
.Fields("TELEPHONE") = txtphone
.Fields("BIRTH_DATE") = txtdob
.Fields("SEX") = txtgender
.Fields("DECEASED") = txtdeceased
.Fields("SEX") = txtgender
.Fields("HEIGHT") = txtheight
.Fields("WEIGHT") = txtweight
.Fields("EYE_COLOR") = txteyecolor
.Fields("HAIR_COLOR") = txthaircolor
.Fields("LICENSE_TYPE") = txtltype
.Fields("SERIAL_NUMBER") = txtlnumber
.Fields("PURCHASE_DATE") = txtpurchasedate
.Fields("PURCHASE_AMOUNT") = txtpurchaseamount
'.Fields("[dbo_PURCHASE_DATA].[NAME_CODE]") = namecode
.Fields("STATUS") = txtstatus
.Fields("STATUS_DATE") = txtstatusdate
.Update
End With
End If
MsgBox "Successfully added", vbOKOnly, "New record Added"
rst.Close
Set rst = Nothing
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdsave_Click:
Exit Sub
Err_cmdsave_Click:
MsgBox Err.Description
Resume Exit_cmdsave_Click
End Sub
Private Sub cmdadd_Click()
On Error GoTo Err_cmdadd_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdadd_Click:
Exit Sub
Err_cmdadd_Click:
MsgBox Err.Description
Resume Exit_cmdadd_Click
End Sub
Comment