Re: Array Help
- From: "Stephen Lynch" <raider1raidospam@xxxxxxxxx>
- Date: Tue, 12 Aug 2008 09:03:06 -0400
Steve & Piet:
I used your code and it worked. Thanks as I attempt to learn about arrays.
If you know of a better way let me know.
"Steve Sanford" <limbim53 at yahoo dot com> wrote in message
news:D4251726-EE2F-444B-B33E-CAC5758461A9@xxxxxxxxxxxxxxxx
Stephen,
I am with Pieter in that I don't understand what you are trying to do. But
I
have a little different take on what you posted. Maybe this will help:
(watch for line wrap) !!!!! mostly untested code !!!!
'-----beg code-------------------------------------
Option Compare Database
Option Explicit
Private Sub AddContributionTypes_Click()
On Error GoTo Err_Handler
Dim arrFields(1 To 7) As String
Dim i As Integer
Dim strSQL As String
'Array("Deferral", "Match", "Roth", "SafeMatch", "PS", "MPP", "SafePS")
arrFields(1) = "Deferral"
arrFields(2) = "Match"
arrFields(3) = "Roth"
arrFields(4) = "SafeMatch"
arrFields(5) = "PS"
arrFields(6) = "MPP"
arrFields(7) = "SafePS"
'loop thru array
For i = 1 To UBound(arrFields)
'For multiple records gathered from other tables or external
sources
'For multiple records, the Access "INSERT INTO" SQL query is:
'
'Insert Into TableName (FieldName1, FieldName2) _
'Select FieldName1, FieldName2 From TableName;
strSQL = "INSERT INTO tblContributions (" & arrFields(i) & ")"
strSQL = strSQL & " SELECT " & arrFields(i)
strSQL = strSQL & " FROM tblContributionsPostAll;"
'MsgBox strSQL
CurrentDb.Execute strSQL, dbFailOnError
Next i
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "ERROR: " & Err.Number & " - " & Err.Description
Resume Err_Exit
End Sub
'------end code------------------------------------
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
"Stephen Lynch" wrote:
Instead of adding 15 docmd.runsql statements that use the same query
except
one field is changed for each query, I was thinking that I could loop
though
the query and add a variable for the field name instead.
I am not sure how to do a loop through the array or write any code for it
as
this is the first time I have encountered a need for an array, so I
thought
I would try.
For Each
F1 = Array("Deferral","Match","Roth","SafeMatch","PS","MPP","SafePS")
INSERT INTO tblContributions ( Deferral )
SELECT F1 FROM tblContributionsPostAll;
Next
Back to the books for me.Thanks in advance
.
- References:
- Array Help
- From: Stephen Lynch
- RE: Array Help
- From: Steve Sanford
- Array Help
- Prev by Date: Re: Need help automating a manual process
- Next by Date: Re: Single Front End with multiple Back Ends
- Previous by thread: Re: Array Help
- Next by thread: Single Front End with multiple Back Ends
- Index(es):
Relevant Pages
|