Message appears twice.

G

Guest

Amateur needs help!

I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close and
return to that record on the main client form.

Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at closing
the entry form.

[txtAdding] is a 1 or 0 and is status for use elsewhere.

I cannot see where the problem. Help!

****** code for main client form NotInList ********

Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"

If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd, acDialog,
NewData
Else
Exit Sub
End If
End If

' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" & NewData &
"'")

If IsNull(Result) Then
' If the customer was not created, set the Response argument to suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.

MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub


****** code for client entry form closing command button********

Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID

If Me.Dirty Then Me.Dirty = False 'closes
entry form and finds new client

Forms![frm1 client].Form!txtAdding = 0

With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With

frm.Requery
Set frm = Nothing

DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"

Exit_btnCloseForm_Click:
Exit Sub

Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click

End Sub
 
G

Guest

Thanks for responding.

I added that line. I also identified the variable (Option Explicit) as both
String and Integer. Both returned the same results. The message appears
twice.

I just don't see how its instructed to show twice.
--
Thanks for your help,
Chris


Maurice said:
Chris,

Befor the Exit Sub of the client entry form place: response=acdataerrcontinue
--
Maurice Ausum


Chris said:
Amateur needs help!

I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close and
return to that record on the main client form.

Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at closing
the entry form.

[txtAdding] is a 1 or 0 and is status for use elsewhere.

I cannot see where the problem. Help!

****** code for main client form NotInList ********

Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"

If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd, acDialog,
NewData
Else
Exit Sub
End If
End If

' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" & NewData &
"'")

If IsNull(Result) Then
' If the customer was not created, set the Response argument to suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.

MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub


****** code for client entry form closing command button********

Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID

If Me.Dirty Then Me.Dirty = False 'closes
entry form and finds new client

Forms![frm1 client].Form!txtAdding = 0

With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With

frm.Requery
Set frm = Nothing

DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"

Exit_btnCloseForm_Click:
Exit Sub

Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click

End Sub
 
P

Perry

In yr Client entry form, you use this line:Why do you need this line?
The Client entry form is opened in an acAdd state. If you undo the changes,
the new record isn't saved.
What happens if you leave out this line?

If the above suggestion fails,
here's a slightly different approach; try to implement

[mainform code)
NotInList() event of the combo fires:
Write the new record to the table
Make sure changes are committed
Pickup the ID of the new record
Set the Response parameter to acDataErrAdded
Open the Client Entry form normally, use a filter or a where statement
using the ID

[frm 1 Client entry code]
Let the user do the entry of other client info on the form, don't toggle
the Dirty() property!~
While having a pointer to your mainform (still loaded I presume), you
may need to requery the combo on yr mainform
Set the combo value (on mainform) to the ID you used previously
Close the Client entry form and your back in the mainform with the new
record selected in the combo

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



Chris said:
Thanks for responding.

I added that line. I also identified the variable (Option Explicit) as
both
String and Integer. Both returned the same results. The message appears
twice.

I just don't see how its instructed to show twice.
--
Thanks for your help,
Chris


Maurice said:
Chris,

Befor the Exit Sub of the client entry form place:
response=acdataerrcontinue
--
Maurice Ausum


Chris said:
Amateur needs help!

I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close
and
return to that record on the main client form.

Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at
closing
the entry form.

[txtAdding] is a 1 or 0 and is status for use elsewhere.

I cannot see where the problem. Help!

****** code for main client form NotInList ********

Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"

If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data
entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd,
acDialog,
NewData
Else
Exit Sub
End If
End If

' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" &
NewData &
"'")

If IsNull(Result) Then
' If the customer was not created, set the Response argument to
suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.

MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate
that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub


****** code for client entry form closing command button********

Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID

If Me.Dirty Then Me.Dirty = False
'closes
entry form and finds new client

Forms![frm1 client].Form!txtAdding = 0

With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With

frm.Requery
Set frm = Nothing

DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"

Exit_btnCloseForm_Click:
Exit Sub

Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click

End Sub
 
G

Guest

I appreciate the time you gave me. Using your suggestions and some others I
found I am successful at almost all of it.

I do have a requery dilemma I shall post anew.

Thanks again, your suggestions got me in the correct directions.
--
Thanks for your help,
Chris


Perry said:
In yr Client entry form, you use this line:Why do you need this line?
The Client entry form is opened in an acAdd state. If you undo the changes,
the new record isn't saved.
What happens if you leave out this line?

If the above suggestion fails,
here's a slightly different approach; try to implement

[mainform code)
NotInList() event of the combo fires:
Write the new record to the table
Make sure changes are committed
Pickup the ID of the new record
Set the Response parameter to acDataErrAdded
Open the Client Entry form normally, use a filter or a where statement
using the ID

[frm 1 Client entry code]
Let the user do the entry of other client info on the form, don't toggle
the Dirty() property!~
While having a pointer to your mainform (still loaded I presume), you
may need to requery the combo on yr mainform
Set the combo value (on mainform) to the ID you used previously
Close the Client entry form and your back in the mainform with the new
record selected in the combo

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



Chris said:
Thanks for responding.

I added that line. I also identified the variable (Option Explicit) as
both
String and Integer. Both returned the same results. The message appears
twice.

I just don't see how its instructed to show twice.
--
Thanks for your help,
Chris


Maurice said:
Chris,

Befor the Exit Sub of the client entry form place:
response=acdataerrcontinue
--
Maurice Ausum


:

Amateur needs help!

I have a main client form with combo box that selects client.
When client doesn't exist the NotInList code opens an entry form.
When the entry form is complete the user uses a command button to close
and
return to that record on the main client form.

Everything is as I want, except the message querying whether to add the
NotInList client appears twice: when its not in the list and again at
closing
the entry form.

[txtAdding] is a 1 or 0 and is status for use elsewhere.

I cannot see where the problem. Help!

****** code for main client form NotInList ********

Private Sub cboClient_NotInList(NewData As String, Response As Integer)
Dim Result
Dim msg, CR As String
CR = Chr$(13)

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Ask the user if he or she wishes to add the new customer.
NewData = UCase(NewData)
msg = "'" & NewData & "' is not in the list." & CR & CR
msg = msg & "Do you want to add it?"

If Me.txtAdding = 0 Then
If MsgBox(msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Client form in data
entry
Me.txtAdding = 1
DoCmd.OpenForm "frm1 ClientEntry", , , , acAdd,
acDialog,
NewData
Else
Exit Sub
End If
End If

' Look for the client the user created in the Client form.
Result = DLookup("[ClientID]", "[tbl 1 Client]", "[ClientID]='" &
NewData &
"'")

If IsNull(Result) Then
' If the customer was not created, set the Response argument to
suppress
an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.

MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to indicate
that
new data is being added.
Response = acDataErrAdded
End If
Me.txtAdding = 0
End Sub


****** code for client entry form closing command button********

Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
Dim NewData As String
Dim frm As Form
Set frm = Forms![frm1 client]
NewData = Me.ClientID

If Me.Dirty Then Me.Dirty = False
'closes
entry form and finds new client

Forms![frm1 client].Form!txtAdding = 0

With frm.RecordsetClone
.FindFirst "ClientID=""" & Me.txtClientID & """"
If Not .NoMatch Then frm.Bookmark = .Bookmark
End With

frm.Requery
Set frm = Nothing

DoCmd.GoToRecord acDataForm, "frm1 Client", acNewRec
DoCmd.Close acForm, "frm1 ClientEntry"

Exit_btnCloseForm_Click:
Exit Sub

Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click

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