Save a single form's record

S

scott

I've got a form/subform scenerio in which the first field in the subform is
a "last name, first name" combo followed by several other field controls. If
the user types in a new name instead of selecting one from the combo, the
cmbUser_NotInList sub fires and opens the "userAdd_pop_up" pop-up form to
allow typing in the first and last name. When the close button on the pop-up
form is clicked, the pop-up form is saved, closed and the user is returned
to the form/subform and the user can then enter a value for the next subform
textbox control for a password field.

Problem is, I get the below "ERROR:" because the subform's password field
(as well as several others) have a "no null allowed" data type and Access
gives the error because the subform's record tries to save before the user
gets a chance to fill in the password field and the other fields that come
after the first "last name, first name" combo.

My question is there a way (from the pop-up form) to just save the pop-up's
first, last name, etc. record and not save the underlying subform's record
when the pop-up is closed? When the "DoCmd.RunCommand acCmdSaveRecord" is
fired from the pop-up close event, eventdently it saves any open dirty form.
Even if I comment out the "DoCmd.RunCommand acCmdSaveRecord" command, Access
saves the pop-up form fine, but gives the error before closing.


'**********
ERROR:

Cannot insert the value NULL into column 'userPassword', table 'my table';
column does not allow nulls. INSERT fails.

'**********
CODE:

Private Sub cmd_Close_Click()
' used on pop-up form to save new user and close pop-up form
If Me.Dirty Then
If IsNothing(Me.userFirst) Or IsNothing(Me.userLast) Then
MsgBox "Must have a first and last name to save a record. Click
Cancel to exit without saving.", vbCritical, "SAM"
Exit Sub
ElseIf Len(Me.userFirst) < 1 Or Len(Me.userLast) < 1 Then
MsgBox "Must have a first and last name to save a record. Click
Cancel to exit without saving.", vbCritical, "SAM"
Exit Sub

End If
End If

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, Me.Name

End Sub


Private Sub cmbUser_NotInList(NewData As String, Response As Integer)
Dim strUser As String, strLast As String, strFirst As String, intComma
As Integer
Dim intReturn As Integer, varName As Variant

' used to open pop-up form to add a new user
' parses the name entered and offers to let the user add themselves as a
new user
strUser = NewData
intComma = InStr(strUser, ",")

If intComma = 0 Then
strLast = strUser
Else
strLast = Left(strUser, intComma - 1)
strFirst = Mid(strUser, intComma + 2)
End If

intReturn = MsgBox("The User " & strUser & _
" is not in the system. Do you want to add this User?", _
vbQuestion + vbYesNo, "SAM")

If intReturn = vbYes Then
DoCmd.OpenForm FormName:="userAdd_pop_up", _
DataMode:=acAdd, WindowMode:=acDialog, OpenArgs:=strUser
Response = acDataErrAdded

End If
Exit Sub

Response = acDataErrAdded

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top