PC Review


Reply
Thread Tools Rate Thread

Appending null data and moving!

 
 
Duncs
Guest
Posts: n/a
 
      28th Oct 2010
I have 1 table with address details, in the format:

BuildingName
StreetName
Suburb
Town
County
Postcode

This information gets appended to another table, which has the
following fields for address:

Addr1
Addr2
Addr3
Addr4
Addr5
Addr6
Addr7
Postcode

So far, so good. However, the data needs to be appended as follows:

If BuildingName is not null, put it in Addr1 field.

If BuildingName is null, put Street in Addr1

If Suburb is not null, put it in the Addr2 field

If Suburb is null, put Town in the Addr2 field

And so on.....

I can append the data and then run a series of queries to move the
data along, whihc is time consuming. So, what I want to know is, is
there a way to either:

1. Append the data as above, taking not of null & non null fields
2. Make the update query more intelligent, to run as the one query,
and tidy up all address info

Many TIA for your help.

Duncs
 
Reply With Quote
 
 
 
 
Ken Snell
Guest
Posts: n/a
 
      28th Oct 2010
Use IIf function to make expressions for each field in the append query:
Addr1: IIf(BuildingName Is Null, Street, BuildingName)

Or, use Nz function:
Addr1: Nz(BuildingName, Street)

And so on.
--

Ken Snell
http://www.accessmvp.com/KDSnell/



"Duncs" <(E-Mail Removed)> wrote in message
news:c74269c6-924e-4a70-adeb-(E-Mail Removed)...
>I have 1 table with address details, in the format:
>
> BuildingName
> StreetName
> Suburb
> Town
> County
> Postcode
>
> This information gets appended to another table, which has the
> following fields for address:
>
> Addr1
> Addr2
> Addr3
> Addr4
> Addr5
> Addr6
> Addr7
> Postcode
>
> So far, so good. However, the data needs to be appended as follows:
>
> If BuildingName is not null, put it in Addr1 field.
>
> If BuildingName is null, put Street in Addr1
>
> If Suburb is not null, put it in the Addr2 field
>
> If Suburb is null, put Town in the Addr2 field
>
> And so on.....
>
> I can append the data and then run a series of queries to move the
> data along, whihc is time consuming. So, what I want to know is, is
> there a way to either:
>
> 1. Append the data as above, taking not of null & non null fields
> 2. Make the update query more intelligent, to run as the one query,
> and tidy up all address info
>
> Many TIA for your help.
>
> Duncs



 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      28th Oct 2010
Hope I understood what you wanted.

One method would be to use a VBA function to return the needed values.

In a query you could use something like the following. Since you only have a
max of five address elements I did not bother with Addr6 and Addr7. I also
assume that PostCode would always go into PostCode

INSERT INTO TargetTable (Addr1, Addr2, Addr3, Addr4, Addr5, PostCode)
SELECT fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line1
, fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line2
, fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line3
, fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line4
, fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line5
, PostCode
FROM SourceTable

'ADD this function to a VBA module and save the module with some name other
than the name of the function.

'================= Begin Code ==========================
Public Function fGetNthValue(iItem, ParamArray vValues())
Dim iCounter As Long
Dim iLoop As Long

fGetNthValue = Null
For iLoop = LBound(vValues) To UBound(vValues)
If Len(vValues(iLoop) & vbNullString) > 0 Then
iCounter = iCounter + 1
If iCounter = iItem Then
fGetNthValue = vValues(iLoop)
End If
End If 'length test

Next iLoop

End Function

'====================End Code ===================

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Duncs wrote:
> I have 1 table with address details, in the format:
>
> BuildingName
> StreetName
> Suburb
> Town
> County
> Postcode
>
> This information gets appended to another table, which has the
> following fields for address:
>
> Addr1
> Addr2
> Addr3
> Addr4
> Addr5
> Addr6
> Addr7
> Postcode
>
> So far, so good. However, the data needs to be appended as follows:
>
> If BuildingName is not null, put it in Addr1 field.
>
> If BuildingName is null, put Street in Addr1
>
> If Suburb is not null, put it in the Addr2 field
>
> If Suburb is null, put Town in the Addr2 field
>
> And so on.....
>
> I can append the data and then run a series of queries to move the
> data along, whihc is time consuming. So, what I want to know is, is
> there a way to either:
>
> 1. Append the data as above, taking not of null & non null fields
> 2. Make the update query more intelligent, to run as the one query,
> and tidy up all address info
>
> Many TIA for your help.
>
> Duncs

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      28th Oct 2010
Whoops! I missed setting the section number in the sample query.

INSERT INTO TargetTable (Addr1, Addr2, Addr3, Addr4, Addr5, PostCode)
SELECT fGetNthValue(1,BuildingName,StreetName,Suburb,Town,County) as Line1
, fGetNthValue(2,BuildingName,StreetName,Suburb,Town,County) as Line2
, fGetNthValue(3,BuildingName,StreetName,Suburb,Town,County) as Line3
, fGetNthValue(4,BuildingName,StreetName,Suburb,Town,County) as Line4
, fGetNthValue(5,BuildingName,StreetName,Suburb,Town,County) as Line5
, PostCode
FROM SourceTable

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
Reply With Quote
 
Duncs
Guest
Posts: n/a
 
      29th Oct 2010
Guys,

Thanks for your suggestions. Two great ideas...in terms of
simplicity, Ken's idea fitted well. However, in terms of future use,
John's VBA code looks good and I can see plenty of uses for it.

Once again, the group haven't dissapointed me with the speed and
quality of the replies received.

Many thanks

Duncs


On 28 Oct, 14:20, Duncs <true.kilted.s...@gmail.com> wrote:
> I have 1 table with address details, in the format:
>
> BuildingName
> StreetName
> Suburb
> Town
> County
> Postcode
>
> This information gets appended to another table, which has the
> following fields for address:
>
> Addr1
> Addr2
> Addr3
> Addr4
> Addr5
> Addr6
> Addr7
> Postcode
>
> So far, so good. *However, the data needs to be appended as follows:
>
> If BuildingName is not null, put it in Addr1 field.
>
> If BuildingName is null, put Street in Addr1
>
> If Suburb is not null, put it in the Addr2 field
>
> If Suburb is null, put Town in the Addr2 field
>
> And so on.....
>
> I can append the data and then run a series of queries to move the
> data along, whihc is time consuming. *So, what I want to know is, is
> there a way to either:
>
> 1. Append the data as above, taking not of null & non null fields
> 2. Make the update query more intelligent, to run as the one query,
> and tidy up all address info
>
> Many TIA for your help.
>
> Duncs


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted Microsoft ASP .NET 0 6th Jan 2008 04:45 AM
al.exe appending extra null bytes to file manifest file version catphive@gmail.com Microsoft Dot NET 0 1st Aug 2006 07:38 AM
Appending Access data from regularly updated Excel data =?Utf-8?B?Z21ldHRsZXI=?= Microsoft Access External Data 1 28th Jun 2006 01:13 PM
Appending Null Values Magic Microsoft Access Form Coding 0 24th Sep 2003 03:31 PM
Appending a blank (null) date to a SQL Server 2000 smalldatetime Field R Bolling Microsoft Access Queries 5 3rd Aug 2003 10:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:00 PM.