Code to add and verify existing data



Hello,
I need some help. I have a form named MASTER based on a table also
called MASTER.
A control of my form in names SSN which stores the client SSN.

On the same form I have placed a subform which has its record source to
a table named 21.

What I am trying to do is:
When I enter a new record in my form MASTER, the code should:
1) Verify if in table 21 a record with that SSN already exists.
If YES, skip the code and do not add the SSN. If NO, well, run the
appendquery.

2) At the same time, verify if a record with that SSN already exists in
table MASTER. If NO, add the data, if YES, abort the code and exit the
form.

The form EForms is a menu form I use to access the records.


This is the code. Something is not going right, I think with the end if
functions. Any help? I have placed the code in the AfterUpdate event of
my control SSN.

Dim mydb As DAO.Database, MyRs As DAO.Recordset
Dim strCode As String
Dim strFilter As String
Dim stDocName As String
Dim stLinkCriteria As String

Set mydb = CurrentDb
Set MyRs = mydb.OpenRecordset("master")

stDocName = "MASTER"

stLinkCriteria = "[SSN]=" & "'" & Me![SSN] & "'"



DoCmd.OpenForm stDocName, , , stLinkCriteria

If Not IsNull(DLookup("[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS").Visible = False
Else
If IsNull(DLookup("[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Appendssa21tax")
End If
End If

If Not IsNull(DLookup("[SSN]", "MASTER", "[SSN] = '" & Me!SSN & "'"))
Then
MsgBox "Sorry! A record with this SSN is already in file. Retrive case
from E-Forms Menu.", vbOKOnly, "Warning"
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.Close
End If
Forms!eforms.lstPreInterview.Value = Null
DoCmd.Close
DoCmd.OpenForm ("Eforms")
DoCmd.RunMacro ("CloseEforms")
DoCmd.OpenForm ("Eforms")
End If

Thanks.

.



Relevant Pages

  • Re: Extract SSNs from a free form text field...
    ... >These are a few of the ways the SSN could appear in the field. ... string of nine digits after an "SS". ... Ensure your project is highlighted in the project explorer window, then, from ... Dim str As String ...
    (microsoft.public.excel.misc)
  • VB to search Excell Sheets
    ... The employees will enter the last 4 numbers of the SSN (Readout) ... Each sheet in the book is named as the last 4 numbers of the SSN. ... Dim m_XLWorkbook As Excel.Workbook ... Dim FileNamePath As String ...
    (microsoft.public.vb.general.discussion)
  • Re: About my Database
    ... Hi Robert! ... It looks to me like you might have a structural problem - I'm not sure that ... - make the Basics table the Master with key on SSN ...
    (microsoft.public.access.gettingstarted)
  • Re: Help needed with query design
    ... Ok so SSN should uniquely identify the records. ... The SQL to show Master Records that have been dropped would be ... In the query grid ... Each Members records can change ...
    (microsoft.public.access.queries)
  • Code to verify if record exists
    ... In the active form the ssn fields is ... ssn is already present in the table MASTER. ... Dim strCode As String ...
    (comp.databases.ms-access)