T
Thurman
Hello,
I have a form where a user enters names into my database.
The names may be new or they may already exist in the
database. Names are entered in tbxFirstName and
tbxLastName on the form and the ID for the record is
autonumber. If a name is new, a popup form is supposed to
open so that the user can assign the new person to an
apartment. If the name is already there, the user needs to
be reminded of this fact and then choose between leaving
the record as it is or assigning the person to a different
apartment.
So far I have been using the DLookup function and Is
NotNull to determine which commands to follow. It works if
the name IS already there. But if the name is new, it
doesn't work. Because the autonumber field automatically
updates when a character is entered in either tbxFirstName
or tbxLastName, the DLookup rightly returns that the record
already exists. Following that, however, it falls apart
because, in fact, the data has not yet been committed to
the database. Can someone help me out with this? My code is:
Private Sub btnAssignApartment_Click()
Dim stDocName, Msg, CR As String
CR = Chr$(13)
strFirstName = Me.tbxFirstName 'global variable
strLastName = Me.tbxLastName ' global variable
stDocName = "frmPopUpTenantApartment"
Msg = "'" & strFirstName & " " & strLastName & "' already
exists in the database." & CR & CR
Msg = Msg & "Would you like to assign this tenant to a
different apartment?" & CR
Response = MsgBox(Msg, vbYesNo, "Duplicate Name")
If Not IsNull(DLookup("TenantID", tblTenants", "FirstName =
'" & Me.tbxFirstName & "' And LastName = '" &
Me.tbxLastName & :;) Then
If Response = vbNo Then 'tenant not new, apt the same
Me.Undo
DoCmd.Close acForm, "frmPopUpAddTenants"
Elseif Response = vbYes Then 'tenant not new, apt is new
DoCmd.Close acForm, "frmPopUpAddTenants"
DoCmd.OpenForm stDocName
End If
Else 'tenant is new, need to assign apt
DoCmd.OpenForm stDocName
End If
End Sub
THANKS IN ADVANCE!
Th.
I have a form where a user enters names into my database.
The names may be new or they may already exist in the
database. Names are entered in tbxFirstName and
tbxLastName on the form and the ID for the record is
autonumber. If a name is new, a popup form is supposed to
open so that the user can assign the new person to an
apartment. If the name is already there, the user needs to
be reminded of this fact and then choose between leaving
the record as it is or assigning the person to a different
apartment.
So far I have been using the DLookup function and Is
NotNull to determine which commands to follow. It works if
the name IS already there. But if the name is new, it
doesn't work. Because the autonumber field automatically
updates when a character is entered in either tbxFirstName
or tbxLastName, the DLookup rightly returns that the record
already exists. Following that, however, it falls apart
because, in fact, the data has not yet been committed to
the database. Can someone help me out with this? My code is:
Private Sub btnAssignApartment_Click()
Dim stDocName, Msg, CR As String
CR = Chr$(13)
strFirstName = Me.tbxFirstName 'global variable
strLastName = Me.tbxLastName ' global variable
stDocName = "frmPopUpTenantApartment"
Msg = "'" & strFirstName & " " & strLastName & "' already
exists in the database." & CR & CR
Msg = Msg & "Would you like to assign this tenant to a
different apartment?" & CR
Response = MsgBox(Msg, vbYesNo, "Duplicate Name")
If Not IsNull(DLookup("TenantID", tblTenants", "FirstName =
'" & Me.tbxFirstName & "' And LastName = '" &
Me.tbxLastName & :;) Then
If Response = vbNo Then 'tenant not new, apt the same
Me.Undo
DoCmd.Close acForm, "frmPopUpAddTenants"
Elseif Response = vbYes Then 'tenant not new, apt is new
DoCmd.Close acForm, "frmPopUpAddTenants"
DoCmd.OpenForm stDocName
End If
Else 'tenant is new, need to assign apt
DoCmd.OpenForm stDocName
End If
End Sub
THANKS IN ADVANCE!
Th.