473,750 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Probably an easy answer - Form and update question

I hope there is an answer out there....

I have a simple database structured like this (non relevant tables and
fields omitted)

Members table
memberID
memberFname
memberLname
memberNokID
memberDob

Next of Kin table
nokID
nokFname
nokLname
nokAddress
nokTown
nokCounty

memberID and nokID are primary keys and autonumber for the tables.
memberNokID is a foriegn key in the members table for the nokID in the
next of kin table.

I then have a single form where users enter data for the member and
the next of kin (also there are school, class, doctor etc but not
relevant to this issue)

What I am trying to achieve is when a user types in the address line
it checks the nextofkin table to determine if the address is already
in the database and if so populate the values from that address into
the other fields. I can do this with some code for the beforeupdate
event:
Extract >>
strAddress = [nokAddress]
strLookup = DLookup("nokAdd ress", "nextofkin" , "nokAddress ='" &
strAddress_ & "'")

I can test this for a match and populate the other fields on the form
ok with
If (Not IsNull(strTown) ) Then Me![nokTown] = strTown
Of course what i really need to do is to insert the nokID of the
existing record into the memberNokID value for the members table, that
way the same address only appears once in the table. (no duplication)

When I try the code


If (Not IsNull(intNOK)) Then Me![memberNokID] = intNOKID


I get error 3341 and a message stating the current field must match
the join key nokID.

I am stumped and have got into a mess trying to fix this one! Could it
be something to to with positioning the current (focussed?) field or
am I going about this the completely wrong way. I DONT want to use a
combo box with a noinlist event, but a way to automatically test if
the Next of Kin is already listed and use the listing as a reference
in the members table to avoid duplication in the next of kin table.

It is possible that > 1 member have the same next of kin and also that
there are > 1 last names for next of kin which are the same. The only
unique thing is the address line.

Full code I'm using is:

Private Sub nokAddress_Befo reUpdate(Cancel As Integer)
Dim strLookup, strAddress, strTown, strCounty, strPostcode As String
Dim intNOKID As Integer
Dim updRecord As Byte

strAddress = [nokAddress]
strLookup = DLookup("nokAdd ress", "nextofkin" , "nokAddress ='" &
strAddress & "'")
If strAddress = strLookup Then

updRecord = MsgBox("A member next of Kin at this address is
already listed. Use the existing data?", vbOKCancel, "Record
Modification")
If updRecord = vbCancel Then
Cancel = True
End If
intNOKID = DLookup("nokId" , "nextofkin" , "nokAddress ='" &
strAddress & "'")
strTown = DLookup("nokTow n", "nextofkin" , "nokAddress ='" &
strAddress & "'")
strCounty = DLookup("nokCou nty", "nextofkin" , "nokAddress ='" &
strAddress & "'")
strPostcode = DLookup("nokPos tcode", "nextofkin" ,
"nokAddress ='" & strAddress & "'")
If (Not IsNull(intNOK)) Then Me![memberNokID] = intNOKID
If (Not IsNull(strTown) ) Then Me![nokTown] = strTown
If (Not IsNull(strCount y)) Then Me![nokCounty] = strCounty
If (Not IsNull(strPostc ode)) Then Me![nokPostcode] =
strPostcode

End If

End Sub
Thanks in advance for any suggestions.

Andy Proctor
Nov 13 '05 #1
4 2730
rkc

"Andy Proctor" <ap******@hotma il.com> wrote in message
news:dd******** *************** ***@posting.goo gle.com...
I hope there is an answer out there....

I have a simple database structured like this (non relevant tables and
fields omitted)

Members table
memberID
memberFname
memberLname
memberNokID
memberDob

Next of Kin table
nokID
nokFname
nokLname
nokAddress
nokTown
nokCounty

memberID and nokID are primary keys and autonumber for the tables.
memberNokID is a foriegn key in the members table for the nokID in the
next of kin table.

I then have a single form where users enter data for the member and
the next of kin (also there are school, class, doctor etc but not
relevant to this issue)

What I am trying to achieve is when a user types in the address line
it checks the nextofkin table to determine if the address is already
in the database and if so populate the values from that address into
the other fields. I can do this with some code for the beforeupdate
event:
Extract >>
strAddress = [nokAddress]
strLookup = DLookup("nokAdd ress", "nextofkin" , "nokAddress ='" &
strAddress_ & "'")

I can test this for a match and populate the other fields on the form
ok with
If (Not IsNull(strTown) ) Then Me![nokTown] = strTown>
Of course what i really need to do is to insert the nokID of the
existing record into the memberNokID value for the members table, that
way the same address only appears once in the table. (no duplication)

When I try the code

If (Not IsNull(intNOK)) Then Me![memberNokID] = intNOKID


I get error 3341 and a message stating the current field must match
the join key nokID.

I am stumped and have got into a mess trying to fix this one! Could it
be something to to with positioning the current (focussed?) field or
am I going about this the completely wrong way. I DONT want to use a
combo box with a noinlist event, but a way to automatically test if
the Next of Kin is already listed and use the listing as a reference
in the members table to avoid duplication in the next of kin table.

It is possible that > 1 member have the same next of kin and also that
there are > 1 last names for next of kin which are the same. The only
unique thing is the address line.

Full code I'm using is:

Private Sub nokAddress_Befo reUpdate(Cancel As Integer)
Dim strLookup, strAddress, strTown, strCounty, strPostcode As String
Dim intNOKID As Integer
Dim updRecord As Byte

strAddress = [nokAddress]
strLookup = DLookup("nokAdd ress", "nextofkin" , "nokAddress ='" &
strAddress & "'")
If strAddress = strLookup Then

updRecord = MsgBox("A member next of Kin at this address is
already listed. Use the existing data?", vbOKCancel, "Record
Modification")
If updRecord = vbCancel Then
Cancel = True
End If
intNOKID = DLookup("nokId" , "nextofkin" , "nokAddress ='" &
strAddress & "'")
strTown = DLookup("nokTow n", "nextofkin" , "nokAddress ='" &
strAddress & "'")
strCounty = DLookup("nokCou nty", "nextofkin" , "nokAddress ='" &
strAddress & "'")
strPostcode = DLookup("nokPos tcode", "nextofkin" ,
"nokAddress ='" & strAddress & "'")
If (Not IsNull(intNOK)) Then Me![memberNokID] = intNOKID
If (Not IsNull(strTown) ) Then Me![nokTown] = strTown
If (Not IsNull(strCount y)) Then Me![nokCounty] = strCounty
If (Not IsNull(strPostc ode)) Then Me![nokPostcode] =
strPostcode

End If

End Sub


So you have a single form based on a query that joins the Members
and NextOfKin tables? What's the query look like? What happens
if you enter nothing but a value for memberNokID in a new record
and move out of the textbox for the field?

I'm guessing the rest of the fields are filled in automagically.


Nov 13 '05 #2
>
So you have a single form based on a query that joins the Members
and NextOfKin tables? What's the query look like? What happens
if you enter nothing but a value for memberNokID in a new record
and move out of the textbox for the field?

I'm guessing the rest of the fields are filled in automagically.


Thanks for the reply. Yes you are correct. (query posted below) If I
just do that then yes the fields get filled in as normal and all is
ok, but that's just using id numbers and not the address. I am not
sure if the way I'm addressing the solution is valid though as I've
made no progress.

What would be the way to get the data entry checked against the
nextofkin table on the address line? Maybe I do need to have a combo
box after all, ??

Here is the query for the form: (this is the full query including the
fields/tables I left out of the original post)

SELECT [members].[memberID], [members].[memberFname],
[members].[memberLname], [members].[memberDob], [members].[memberSex],
[members].[memberDateJoine d], [members].[memberNokID],
[members].[memberMedical], [members].[memberSchoolId],
[members].[memberDoctorId], [members].[memberStandard],
[members].[memberDocName], [nextofkin].[nokID],
[members].[memberClassId], [nextofkin].[nokTitle],
[nextofkin].[nokFname], [nextofkin].[nokLname],
[nextofkin].[nokAddress], [nextofkin].[nokTown],
[nextofkin].[nokCounty], [nextofkin].[nokPostcode],
[nextofkin].[nokPhoneNo], [nextofkin].[nokMobileNo],
[nextofkin].[nokEmail], [schools].[schoolName],
[schools].[schoolAddress], [schools].[schoolTown],
[schools].[schoolCounty], [schools].[schoolPostcode],
[schools].[schoolPhoneNo], [doctors].[doctorSurgeryNa me],
[doctors].[doctorAddress], [doctors].[doctorTown],
[doctors].[doctorCounty], [doctors].[doctorPostcode],
[doctors].[doctorPhone], [classes].[classType], [classes].[classDay],
[classes].[classTime], [standards].[memberStandard] FROM standards
INNER JOIN (schools INNER JOIN (nextofkin INNER JOIN (doctors INNER
JOIN (classes INNER JOIN members ON
[classes].[classId]=[members].[memberClassId]) ON
[doctors].[doctorId]=[members].[memberDoctorId]) ON
[nextofkin].[nokID]=[members].[memberNokID]) ON
[schools].[schoolId]=[members].[memberSchoolId]) ON
[standards].[memberStandardI d]=[members].[memberStandard];
Any help gratefully received! I think that I'm not seeing the wood for
the trees and that the answer is there but I'm not seeing it.

Thanks

Andy
Nov 13 '05 #3
rkc

"Andy Proctor" <ap******@hotma il.com> wrote in message
news:dd******** *************** ***@posting.goo gle.com...

So you have a single form based on a query that joins the Members
and NextOfKin tables? What's the query look like? What happens
if you enter nothing but a value for memberNokID in a new record
and move out of the textbox for the field?

I'm guessing the rest of the fields are filled in automagically.
Thanks for the reply. Yes you are correct. (query posted below) If I
just do that then yes the fields get filled in as normal and all is
ok, but that's just using id numbers and not the address. I am not
sure if the way I'm addressing the solution is valid though as I've
made no progress.

What would be the way to get the data entry checked against the
nextofkin table on the address line? Maybe I do need to have a combo
box after all, ??

Here is the query for the form: (this is the full query including the
fields/tables I left out of the original post)

<snip query>
Any help gratefully received! I think that I'm not seeing the wood for
the trees and that the answer is there but I'm not seeing it.


I can't tell you how to re-work your query so that your problem
goes away. I can tell you that if you enter the address in an unbound
textbox and then do the lookup that the sympton goes away. But it
only goes away if none of the other bound fields have been entered
before hand.

You might want to try breaking up your query and using one or more
subforms to do your entry.


Nov 13 '05 #4
> I can't tell you how to re-work your query so that your problem
goes away. I can tell you that if you enter the address in an unbound
textbox and then do the lookup that the sympton goes away. But it
only goes away if none of the other bound fields have been entered
before hand.

You might want to try breaking up your query and using one or more
subforms to do your entry.


Thanks for the help. I think there was a flaw in my fundemental design of
the forms to be honest. I have messed around with a few today and the nokID
was already allocated to the form record before I check the data so when
trying to set the nokID value no wonder there is an error!! duh! Stupid boy!

I have to reorganise my structure to try and strip out the unique part of
the data..i.e. the address info into a separate table I think, and then I
can check on that. Thats the theory anyway. When I check on it I can use the
notinlist event I hope. I'm going to search the group now to see if i can
find a way to trigger the search on say only after the first 2 characters of
the address are entered as then if the user enters 34 as the house number,
if any other 34's exist is will look for them.

Any thoughts?

Thanks

Andy
Nov 13 '05 #5

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

Similar topics

4
4296
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field that has been modified/clicked the form doesn't always submit. When it does work, a Stored procedure is passed form variables and updates to the db are made. When it doesn't, its as if the form wasn't submitted, it reloads and resets the page, but...
7
1436
by: Bastard_Toadflax | last post by:
I'm making a database for a work project, and am having some difficulties (note: I am at the novice end of the MS Access users spectrum). Basically, what I have to do is make a list of managers in the organisation, their contact details, and so on. So the fields I have are as follows: First Name Surname Section Telephone number Department
2
1143
by: Scott Manson | last post by:
I am working on a database access program using C# and am having a few problems. I am collecting data that may or may not be in order and may or may not be in the database. I have 2 classes that take care of the parsing of the data and everything is working fine I can query my DB and such but I am having trouble with adding an entry if the entry is not in the DB. I currently am having problems with not getting the correct data at
1
1761
by: jm | last post by:
Easy probably, please read on. I know some of you have commented already about some of my socket question. I appreciate that. I have a Form1: static void Main() { Application.Run(new Form1()); clsListening.AsynchronousSocketListener.StartListening();
7
1283
by: Trev | last post by:
Hey, I just want to know (i know i should know this) how can i show up another form? I have 2 forms and the first one has a button on it that when i click the button i want the second form to show up (and the first form disappear), and i also want another button on the second form to return to the first form.
10
1178
by: patang | last post by:
Question 1 I have two forms, let say Form1 and Form2. There is datetimepicker control on Form2. In the Load Event of Form2 I have set the default value of datetimepicker control to NOW. So as expected when I open the form the default value is set to today's date. Now I sometimes also call Form2 from Form1. Ok now here is my problem. Actually when I call Form2 from within Form1 I want to set the set the value of datetimepicker control to...
10
1640
by: cj | last post by:
I have lots of tables to copy from one server to another. The new tables have been created to match the old ones. I practiced with one table. I created the select command (select * from tableA) and Visual Basic .NET created an update command--very long as there are a lot of fields. Now there are more large tables to copy. Is there an easy way to have Visual Basic create these update commands itself for the other tables with out...
9
2781
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub respond to that button’s Click event. My main page has only one line:
0
231
by: TonyJ | last post by:
Hello! I use VS2005 and C#. I'm looking at ADO.NET and have found some test tutorial on microsoft MSDN. It can be found on google when searching for "Walkthrough: Saving Data to a Database (Single Table)" You must have access to the Northwind sample database.
0
9584
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...
0
9398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9345
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,...
0
9257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8265
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6811
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
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4894
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3327
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

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.