K
kirk Wilson
This Access 2K code is tied to a command button that closes the form
New_Customer. The form has two unbound text boxes, (fname) and
(lname). It also has a bound TextBox named Record_id# whos data source
is the autonumber primary key for the table that contains Location
Information. The relationship is a one "Location" to many "Contacts"
in the Master_Contacts table. The Current event of New_Customer Form
uses a DoCmd to open the form & place it at a new record. The user
enters first & last name info in the approproiate text boxes and then
clicks the close command button. The click event for the close command
button is supposed to add the first name, last name, address key link,
and the byte number 1 for the field [Type] as a new record to the
table Master_Contacts. The code compiles without error and executes
without any runtime errors. I can see the correct values in debug for
[LastName],[FisrtName],[Address], & [Type] but no new record is
created. The help system seems to offer help for DAO only. What have I
done wrong here?
Sub CloseForm_Click()
On Error GoTo Err_Command60_Click
Dim rstRecordSet As ADODB.Recordset
Set rstRecordSet = New ADODB.Recordset
Dim strIndex As String
Dim ctlForm As Object
Dim strLname As String
Dim strFname As String
Set ctlForm = Forms![New_Customer]
strIndex = ctlForm.[Record_id#]
strLname = ctlForm.lname
strFname = ctlForm.fname
With rstRecordSet
Set .ActiveConnection = CurrentProject.Connection
.Source = "Master_Contacts"
.CursorLocation = adUseServer
.LockType = adLockBatchOptimistic
.CursorType = adOpenKeyset
.Open
.AddNew
.Fields("LastName") = strLname
.Fields("FirstName") = strFname
.Fields("Address") = strIndex
.Fields("Type") = 1
.Update
End With
rstRecordSet.Close
Set rstRecordSet = Nothing
DoCmd.Close
Set ctlForm = Forms![Edit_Customer]
ctlForm.Requery
Forms![Edit_Customer]![Record_id#].SetFocus
DoCmd.FindRecord strIndex, , , , , acCurrent
Exit_Command60_Click:
Exit Sub
Err_Command60_Click:
MsgBox Err.Description
Resume Exit_Command60_Click
End Sub
Private Sub Form_Current()
Dim str_Form As String
str_Form = "new_customer"
DoCmd.GoToRecord acForm, str_Form, acNewRec
End Sub
New_Customer. The form has two unbound text boxes, (fname) and
(lname). It also has a bound TextBox named Record_id# whos data source
is the autonumber primary key for the table that contains Location
Information. The relationship is a one "Location" to many "Contacts"
in the Master_Contacts table. The Current event of New_Customer Form
uses a DoCmd to open the form & place it at a new record. The user
enters first & last name info in the approproiate text boxes and then
clicks the close command button. The click event for the close command
button is supposed to add the first name, last name, address key link,
and the byte number 1 for the field [Type] as a new record to the
table Master_Contacts. The code compiles without error and executes
without any runtime errors. I can see the correct values in debug for
[LastName],[FisrtName],[Address], & [Type] but no new record is
created. The help system seems to offer help for DAO only. What have I
done wrong here?
Sub CloseForm_Click()
On Error GoTo Err_Command60_Click
Dim rstRecordSet As ADODB.Recordset
Set rstRecordSet = New ADODB.Recordset
Dim strIndex As String
Dim ctlForm As Object
Dim strLname As String
Dim strFname As String
Set ctlForm = Forms![New_Customer]
strIndex = ctlForm.[Record_id#]
strLname = ctlForm.lname
strFname = ctlForm.fname
With rstRecordSet
Set .ActiveConnection = CurrentProject.Connection
.Source = "Master_Contacts"
.CursorLocation = adUseServer
.LockType = adLockBatchOptimistic
.CursorType = adOpenKeyset
.Open
.AddNew
.Fields("LastName") = strLname
.Fields("FirstName") = strFname
.Fields("Address") = strIndex
.Fields("Type") = 1
.Update
End With
rstRecordSet.Close
Set rstRecordSet = Nothing
DoCmd.Close
Set ctlForm = Forms![Edit_Customer]
ctlForm.Requery
Forms![Edit_Customer]![Record_id#].SetFocus
DoCmd.FindRecord strIndex, , , , , acCurrent
Exit_Command60_Click:
Exit Sub
Err_Command60_Click:
MsgBox Err.Description
Resume Exit_Command60_Click
End Sub
Private Sub Form_Current()
Dim str_Form As String
str_Form = "new_customer"
DoCmd.GoToRecord acForm, str_Form, acNewRec
End Sub