Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating duplicate lines? 1

Status
Not open for further replies.

SeeThru

IS-IT--Management
May 2, 2002
585
GB
Odd one for all the SQL specialists....

I have a table like this

Name Address NumberLetters


I need to create a Query for a mail merge that shows one row per letter required. For instance, the follwoing data:

Mr Smith 1 The Street 5

Would create tho following query for merging

Mr Smith 1 The Street
Mr Smith 1 The Street
Mr Smith 1 The Street
Mr Smith 1 The Street
Mr Smith 1 The Street

Any ideas?

The number of letters is quite variable - ideally, the elegant solution would accomodate infinity-1 number of letters...

SeeThru
Synergy Connections Ltd - Telemarketing Services
 
I think you're pretty much stuck with code.
Code:
Sub SomeSub()
BuildMailMerge "Mr Smith", "1 The Street", 5
BuildMailMerge "Mrs Jones", "2 The Avenue", 3
[COLOR=black cyan]' etc.[/color]
End Sub


Public Sub BuildMailMerge (Customer As String, _
                           Address As String, _
                           Copies As Long)

Dim SQL As String
Dim n   As Long

SQL = "INSERT INTO mmTable (Customer, Address) " & _
      "VALUES ( '" & Customer & "', '" & Address & "')"

For n = 1 To Copies
   CurrentDb.Execute SQL
Next n

Exit Sub

Then use "mmTable" as the recordsource for your mail merge.

Can't quite accommodate infinity - 1 ...
Will 9,223,372,036,854,775,807 be enough?
 
Create a table of numbers and then:
SELECT A.Name, A.Address
FROM yourTable AS A INNER JOIN tblNumbers AS B ON A.NumberLetters <= B.Number

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Nice PH- I'll try that - if not I'll have to build a temporary table - they are such a pain due to the bloat they create.

SeeThru
Synergy Connections Ltd - Telemarketing Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top