J
Joan
The situation I'm working with is rather difficult to explain, but please
bear with me. I will try to explain it as best as I can. I am working with
an AddLitters form, and AddDam and AddSire forms. When entering information
on the AddLitters form there are two combo-boxes called DamRegNumber and
SireRegNum to enter the Sire and Dam of the Litter. I have code written in
both of their NotInList events that displays a message asking the user if
they would like to enter a new sire or dam if the number entered is not in
the Sires or Dams tables. If the user clicks "Yes" then either a
AddDamwAddLitter or a AddSirewAddLitter form opens depending upon which
combo box a number is entered in. Each of these forms has a txtRegNumber
for the new Sire or Dam and two combo-boxes (called SireRegNum and
DamRegNum) to enter the registration numbers(primary key) of the new Sire's
or new Dam's father and mother (sire and dam). These combo boxes also have
code for their NotInList event to open a form to add them if they are also
NOT in the table.
This process can keep repeating itself and starts with the AddLitter form.
However, the same process could start with either the AddDam form or the Add
Sire form. Consider the AddDam form where if for instance the registration
number of the new Dam's dam is not in the table, a form could open in which
to add the new Dam's dam. Likewise if the new Dam's sire is not in the list.
Below I've copied my code from the AddDamwAddLitter form (varNewValue and
varDNewValue are both global public variables). Is there a simpler way to do
this, considering all the reiterations of this process that could occur? As
you can see on AddDamwAddLitter form's On Close event, I requery the
AddLitters![DamRegNumber] and set the text property of
AddLitters![DamRegNumber] to varNewValue. Doing it the way I am, I need a
different AddDam or AddSire form for each different instance because of the
OnClose event referring to the form from which the present form was called.
For instance now I have an AddDam form, an AddDamwAddLitter form , and an
AddDamwAddDam form. Likewise for adding Sires. And each of these forms also
have combo boxes with NotInList events for it's Dam and Sire. This is
getting way too cumbersome and confusing to code. Is there a better way to
code this so that I only need to use one AddDam or one AddSire form??
Joan
<Option Compare Database
<Option Explicit
<Private Sub DamRegNum_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Dam Reg Number]", "Dams", "DamRegNum=""" & NewData
& """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Dam list. Would you like
to add it?", 33) <> 1 Then
< Me.DamRegNum.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varDNewValue = Me!DamRegNum.Text
< Me.DamRegNum.Text = " "
< DoCmd.OpenForm "AddDamwAddDam", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub
<Private Sub Form_Close()
< Forms![AddLitter]![DamRegNumber].Requery
< Forms![AddLitter]![DamRegNumber].Text = varNewValue
<End Sub
<Private Sub SireRegNum_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Sire Reg Number]", "Sires", "SireRegNum=""" &
NewData & """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Sire list. Would you like
to add it?", 33) <> 1 Then
< Me.SireRegNum.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varSNewValue = Me!SireRegNum.Text
< Me.SireRegNum.Text = " "
< DoCmd.OpenForm "AddSire", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub
Below is the code for the AddLitters![DamRegNumber]'s NotInList event:
<Private Sub DamRegNumber_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Dam Reg Number]", "Dams", "DamRegNumber=""" &
NewData & """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Dam list. Would you like
to add it?", 33) <> 1 Then
< Me.DamRegNumber.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varNewValue = Me!DamRegNumber.Text
< Me.DamRegNumber.Text = " "
< DoCmd.OpenForm "AddDamwAddLitter", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub
bear with me. I will try to explain it as best as I can. I am working with
an AddLitters form, and AddDam and AddSire forms. When entering information
on the AddLitters form there are two combo-boxes called DamRegNumber and
SireRegNum to enter the Sire and Dam of the Litter. I have code written in
both of their NotInList events that displays a message asking the user if
they would like to enter a new sire or dam if the number entered is not in
the Sires or Dams tables. If the user clicks "Yes" then either a
AddDamwAddLitter or a AddSirewAddLitter form opens depending upon which
combo box a number is entered in. Each of these forms has a txtRegNumber
for the new Sire or Dam and two combo-boxes (called SireRegNum and
DamRegNum) to enter the registration numbers(primary key) of the new Sire's
or new Dam's father and mother (sire and dam). These combo boxes also have
code for their NotInList event to open a form to add them if they are also
NOT in the table.
This process can keep repeating itself and starts with the AddLitter form.
However, the same process could start with either the AddDam form or the Add
Sire form. Consider the AddDam form where if for instance the registration
number of the new Dam's dam is not in the table, a form could open in which
to add the new Dam's dam. Likewise if the new Dam's sire is not in the list.
Below I've copied my code from the AddDamwAddLitter form (varNewValue and
varDNewValue are both global public variables). Is there a simpler way to do
this, considering all the reiterations of this process that could occur? As
you can see on AddDamwAddLitter form's On Close event, I requery the
AddLitters![DamRegNumber] and set the text property of
AddLitters![DamRegNumber] to varNewValue. Doing it the way I am, I need a
different AddDam or AddSire form for each different instance because of the
OnClose event referring to the form from which the present form was called.
For instance now I have an AddDam form, an AddDamwAddLitter form , and an
AddDamwAddDam form. Likewise for adding Sires. And each of these forms also
have combo boxes with NotInList events for it's Dam and Sire. This is
getting way too cumbersome and confusing to code. Is there a better way to
code this so that I only need to use one AddDam or one AddSire form??
Joan
<Option Compare Database
<Option Explicit
<Private Sub DamRegNum_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Dam Reg Number]", "Dams", "DamRegNum=""" & NewData
& """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Dam list. Would you like
to add it?", 33) <> 1 Then
< Me.DamRegNum.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varDNewValue = Me!DamRegNum.Text
< Me.DamRegNum.Text = " "
< DoCmd.OpenForm "AddDamwAddDam", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub
<Private Sub Form_Close()
< Forms![AddLitter]![DamRegNumber].Requery
< Forms![AddLitter]![DamRegNumber].Text = varNewValue
<End Sub
<Private Sub SireRegNum_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Sire Reg Number]", "Sires", "SireRegNum=""" &
NewData & """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Sire list. Would you like
to add it?", 33) <> 1 Then
< Me.SireRegNum.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varSNewValue = Me!SireRegNum.Text
< Me.SireRegNum.Text = " "
< DoCmd.OpenForm "AddSire", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub
Below is the code for the AddLitters![DamRegNumber]'s NotInList event:
<Private Sub DamRegNumber_NotInList(NewData As String, Response As Integer)
< If Not IsNull(DLookup("[Dam Reg Number]", "Dams", "DamRegNumber=""" &
NewData & """")) Then
< Response = DATA_ERRADDED
< Exit Sub
< End If
< If MsgBox("""" & NewData & """ is not in the Dam list. Would you like
to add it?", 33) <> 1 Then
< Me.DamRegNumber.Text = " "
< Response = DATA_ERRCONTINUE
< Exit Sub
< End If
< varNewValue = Me!DamRegNumber.Text
< Me.DamRegNumber.Text = " "
< DoCmd.OpenForm "AddDamwAddLitter", , , , acFormAdd 'Data Entry Mode
< Response = DATA_ERRCONTINUE
<End Sub