473,756 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input Data from Text File - Checking for Data Already in DB

I'm using A2K.

I'm inputing data from a text file into my DB, and I need to check for
the data already existing in the DB. If it's already in the DB, I
don't want to reenter it.

The two tables being used are tblPersonal and tblListData.
tblPersonal contains names, SSNs, etc. SSN is the PrimaryKey.
tblListData is keyed on the combination of SSN and ExamNum. In
tblListData, an SSN can be paired with more than one ExamNum, but the
combination must be unique.

I need to do this:
If SSN is NOT in tblPersonal Then
add new record in tblPersonal
Else ' SSN is already in DB - check if SSN is already paired with
ExamNum
If the combinaton of SSN and ExamNum is NOT in tblListData Then
add new record in tblListData
End if
End If

The short version of my question is: How can I check programmaticall y
for the existence of the combinaton of SSN and ExamNum in tblListData?

Some details of what I have so far:
To do the first part (If SSN is NOT in tblPersonal then) I've written
a function using the Seek method:
Public Function Exists(strRS As String, _
strIndex As String, _
strTarget As String) As Boolean

' strRS is the table beign searched
' strIndex is the index of the table
' strTarget is the value being searched for

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordse t(strRS)

rs.Index = strIndex
rs.Seek "=", strTarget

If rs.NoMatch = True Then
Exists = False
Else
Exists = True
End If

rs.Close

End Function

and used it like this:
' this code fragment is inside a while loop
' enter data into DB
' if SSN is not already in DB
If Not Exists("tblPers onal", "SSN", strSSN) Then
' create new record in tblPesonal
rsPersonal.AddN ew

rsPersonal!SSN = strSSN
rsPersonal!Elig Name = strName
Nov 13 '05 #1
7 1805
Maybe try using DCount; it's used like this:

if DCount("[SSN]", "tblPersona l", "[SSN] = " & mySSN) = 0 then
.....
end if

if DCount("[SSN]", "tblListDat a", "[SSN] = " & mySSN & " and [ExamNum] = " &
myExamNum) = 0 then
.....
end if

Use single quotes if any of your data is char: e.g.
DCount("[OrderID]", "Orders", "[ShipRegion] = 'CA'")

HTH -Linda
"RBohannon" <ra*****@hotmai l.com> wrote in message
news:ad******** *************** ***@posting.goo gle.com...
I'm using A2K.

I'm inputing data from a text file into my DB, and I need to check for
the data already existing in the DB. If it's already in the DB, I
don't want to reenter it.

The two tables being used are tblPersonal and tblListData.
tblPersonal contains names, SSNs, etc. SSN is the PrimaryKey.
tblListData is keyed on the combination of SSN and ExamNum. In
tblListData, an SSN can be paired with more than one ExamNum, but the
combination must be unique.

I need to do this:
If SSN is NOT in tblPersonal Then
add new record in tblPersonal
Else ' SSN is already in DB - check if SSN is already paired with
ExamNum
If the combinaton of SSN and ExamNum is NOT in tblListData Then
add new record in tblListData
End if
End If

The short version of my question is: How can I check programmaticall y
for the existence of the combinaton of SSN and ExamNum in tblListData?

Some details of what I have so far:
To do the first part (If SSN is NOT in tblPersonal then) I've written
a function using the Seek method:
Public Function Exists(strRS As String, _
strIndex As String, _
strTarget As String) As Boolean

' strRS is the table beign searched
' strIndex is the index of the table
' strTarget is the value being searched for

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordse t(strRS)

rs.Index = strIndex
rs.Seek "=", strTarget

If rs.NoMatch = True Then
Exists = False
Else
Exists = True
End If

rs.Close

End Function

and used it like this:
' this code fragment is inside a while loop
' enter data into DB
' if SSN is not already in DB
If Not Exists("tblPers onal", "SSN", strSSN) Then
' create new record in tblPesonal
rsPersonal.AddN ew

rsPersonal!SSN = strSSN
rsPersonal!Elig Name = strName
.
.
.
rsPersonal.Upda te
rsPersonal.Move Next

intCount = intCount + 1

But I don't know how I would check for the combinaton of SSN and
ExamNum in tblListData.

I apologize for the length of this post, and I hope I've been clear
enough.
Any help would be greatly appreciated.

Nov 13 '05 #2
Thanks for your help. I won't have a chance to try this until Monday, 8/23.

Randy
Nov 13 '05 #3
Of course, you could always append to an intermediate table and then
use an outer join to get the records that aren't already in the table
and import just those. All that with maybe two lines of code...

docmd.transferT ext...
docmd.OpenQuery ...
Nov 13 '05 #4
An excellent idea. Thank you.
Of course, you could always append to an intermediate table and then
use an outer join to get the records that aren't already in the table
and import just those. All that with maybe two lines of code...

docmd.transfer Text...
docmd.OpenQuer y ...

Nov 13 '05 #5
I'm getting an error message that says "Error 3464: Data type mismatch
in criteria expression."

My code:
If DCount("[SSN]", "tblListDat a", "[SSN] = " & strSSN & " And
[ExamNum] = " & strExamNum) = 0 then
Nov 13 '05 #6
I got it.

I needed to enclose my criteria expression in single quotes:

If DCount("[SSN]", "tblListDat a", "[SSN] = '" & strSSN & " And
[ExamNum] = " & strExamNum & "'") = 0 Then
Nov 13 '05 #7
Well, it appeared to be working, but it was not. I have finally
figured it out. So, for the benefit of anyone else whom this may
help:
If the criteria is not literal, it must be enclosed in single quotes,
e.g:

If DCount("[SSN]", "tblListDat a", "[[SSN] = '" & strSSN & "' And
[ExamNum] = '" & strExamNum & "'") = 0 Then
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2991
by: lawrence | last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: http://www.ietf.org/rfc/rfc1867.txt Is this (below) addressed to me as a web designer, or is this addressed to the makers of web browsers? Identifying the type of file being uploaded seems way outside of my scope as a PHP coder. Am I
6
2611
by: Jay | last post by:
Hi everybody! Please help me with this problem. I try to write code for server side data validation. Initially, I have a html file called "form.html" which just contains all the necessary fields for user to submit their contact info (name, phone, email, address.....etc...). All user's input will be sent to "processForm.php" using POST. In processForm.php, I want to be able to re-display the form in "form.html" with valid user's input and...
4
4422
by: KathyB | last post by:
Sorry this is a bit of a repost because I wasn't quite accurate in my original. I have an hmtl page with a function to see if there are any input type=text boxes. If so, that means a user did not complete them (once entered, my xsl stylesheet makes them text instead of text input boxes, so there should be NO input text boxes when the user is clicking the FINISH button. I have the following which checks for just INPUT, but how to
2
1268
by: headware | last post by:
I realize that when making a web application, performing input validation in the browser is good because it prevents postbacks. However, input checking that goes beyond making sure a value exists or that it's not alphabetic when it's supposed to be numeric is arguably best left to the business tier code on the server where there is access to other data. My questions, is what's the best way to communicate complicated error checking...
2
42889
by: Jim B | last post by:
I am new to VB.NET and have a question on validating user input from a Text Box. I'm writing a small program where I want to check the users input data and determine if it's an Integer or a Decimal. I guess I want to go one step further than just checking for IsNumeric. I have searched this Work Groups' database and did not find exactly what I need. I have tried GetType, VarType, and the Val Function using the Text Box data, without...
48
2248
by: Michel Rouzic | last post by:
I know it must sound like a newbie question, but I never really had to bother with that before, and I didn't even find an answer in the c.l.c FAQ I'd like to know what's the really proper way for input a string in an array of char that's dynamically allocated. I mean, I wish not to see any such things as char mystring; I don't want to see any number (if possible) I just want to declare something like char *mystring; and then I don't...
2
1490
by: MadMike42 | last post by:
This is really starting to annoy me, I've got a form, that has some input boxes, a example of the code is here:- <form action="admin_save_stock.asp" method="post" name="MyFormData"> <input name="Make" type="text" id="MenuText" value=<% response.write rsTable("Make") %size="50" maxlength="50"> <input name="DateBought" id="MenuText" type="text" value=<% response.write rsTable("DateBought") % size="10" maxlength="10"> </form>
5
1871
by: DavidB | last post by:
I have a situation where a user needs to clone an existing BE database (stored on a server) to his local machine. Assume the followings... User goes into the database FE which has linked BE. BE is stroed on a server. User needs to be able to click a button on the FE that will clone the copy of the BE on the server to C:\. If a copy of the BE already exists at C:\, the clone process should overwrite the existing copy at C:\.
26
3120
by: Bert | last post by:
Hi, I'm unhappy: why doesn't this work? char enc; char temp; for(int i=0;i<10000;i++){ fscanf(in,"%s",&temp); if(temp=='#')break; else
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.