G
Guest
I have a form that adds a new record then I close the form and it saves
another record. Is there a way to prevent this?
another record. Is there a way to prevent this?
I have a form that adds a new record then I close the form and it saves
another record. Is there a way to prevent this?
I have a button with this code behind it that filters:
Me.Filter = "[SSN] = '" & SSN & "'"
Me.FilterOn = True
Me.Refresh
then I have another button that just had the comman
docmd.save
It will filter on the SSN and all of the questions associated with this SSN.
I needed to change on of them then saveto the current record. But it is
saving the questions right but it is adding a blank row such as this
SSN SetA SetB Set3
111111111 2 1 1
111111111
John Vinson said:I have a button with this code behind it that filters:
Me.Filter = "[SSN] = '" & SSN & "'"
Me.FilterOn = True
Me.Refresh
then I have another button that just had the comman
docmd.save
This saves *DESIGN CHANGES* to the structure of the form; it may also
save data to the table, butit's not necessary to have any button to do
so. Just moving off the record or closing the form will save the
record. If you *do* want to save the current record use either
DoCmd.RunCommand acCmdSaveRecord
or
If Me.Dirty Then Me.Dirty = False
It will filter on the SSN and all of the questions associated with this SSN.
I needed to change on of them then saveto the current record. But it is
saving the questions right but it is adding a blank row such as this
SSN SetA SetB Set3
111111111 2 1 1
111111111
I'd be inclined to use a Form with a Subform for this purpose - base a
Form on the "people" table (with the SSN as its primary key) and a
subform on the questions table, using SSN as the master/child link
field. Then you don't need ANY code at all - just enter data and tab
to the next field!
John W. Vinson[MVP]
I am still getting the extra line saving. Here is my code for the button to
close the form and open a new one.
If Len(Me.SSN) = 9 Then
If IsNull(Me.SSN) Then
MsgBox ("Please enter a SSN")
ElseIf IsNull(Me.SetA) Then
MsgBox ("Please select Yes/No from Set A")
ElseIf IsNull(Me.SetB) Then
MsgBox ("Please select Yes/No from Set B")
ElseIf IsNull(Me.SetC) Then
MsgBox ("Please select Yes/No from Set C")
Else
DoCmd.Close
DoCmd.OpenForm ("PHQ")
End If
Else
MsgBox ("Please enter a full SSN")
End If
This is the code to filter the form. I put in a SSN then press this. Then
I change the answers to SetA,B, and C then i hit the button to close the form
and open a new on and it is still adding a blank record like the example.
varResult = DLookup("SSN", "Provider", "SSN = '" & Me.SSN & "'")
If IsNull(varResult) Then
If MsgBox("This is a new SSN. Would you like to add this SSN? " &
SSN, vbYesNo) = vbYes Then
If Len(Me.SSN) = 9 Then
If IsNull(Me.SSN) Then
MsgBox ("Please enter a SSN")
End If
Else
MsgBox ("Please enter a full SSN")
End If
End If
Else
Me.Filter = "[SSN] = '" & SSN & "'"
Me.FilterOn = True
Me.Refresh
End If
John Vinson said:I am still getting the extra line saving. Here is my code for the button to
close the form and open a new one.
If Len(Me.SSN) = 9 Then
If IsNull(Me.SSN) Then
MsgBox ("Please enter a SSN")
ummmm... if the Len of SSN is equal to 9, then you can be absolutely
CERTAIN that this condition will never occur.
ElseIf IsNull(Me.SetA) Then
MsgBox ("Please select Yes/No from Set A")
ElseIf IsNull(Me.SetB) Then
MsgBox ("Please select Yes/No from Set B")
ElseIf IsNull(Me.SetC) Then
MsgBox ("Please select Yes/No from Set C")
Else
And these conditions will be tested one at a time; if both SetA and
SetB are NULL, you'll see only the message from SetA. I'd use separate
If/End If blocks.
DoCmd.Close
DoCmd.OpenForm ("PHQ")
End If
Else
MsgBox ("Please enter a full SSN")
End If
What Event is this code part of? A Click event? I wonder if the test
for null values and invalid SSN's shouldn't be in the Form's
BeforeUpdate event, which can be cancelled (and which will be called
at the line DoCmd.Close).
This is the code to filter the form. I put in a SSN then press this. Then
I change the answers to SetA,B, and C then i hit the button to close the form
and open a new on and it is still adding a blank record like the example.
varResult = DLookup("SSN", "Provider", "SSN = '" & Me.SSN & "'")
If the only point to this form is to select a SSN and open a new form
- then simply make the Form UNBOUND. Am I misunderstanding the purpose
of this form? What's done with the second form?
If IsNull(varResult) Then
If MsgBox("This is a new SSN. Would you like to add this SSN? " &
SSN, vbYesNo) = vbYes Then
If Len(Me.SSN) = 9 Then
If IsNull(Me.SSN) Then
MsgBox ("Please enter a SSN")
End If
Else
MsgBox ("Please enter a full SSN")
End If
End If
Else
Me.Filter = "[SSN] = '" & SSN & "'"
Me.FilterOn = True
Me.Refresh
End If
John W. Vinson[MVP]