pikkhuanloy
Registered User.
- Local time
- Today, 07:34
- Joined
- Mar 30, 2015
- Messages
- 17
Hi guys , as title, I would like to ask you guys whether there is "FOR" loop in Access VBA codes.
It's because currently I have been writing a code to build a loop. and the code is something like :
i got the idea but i dont know how to write the code. Please help me, guys!
Hope to hear from you soon. Thanks
It's because currently I have been writing a code to build a loop. and the code is something like :
Code:
Dim rs As Recordset
Dim strTableFields As String
Dim strOutputTableFields As String
Dim strSQL As String
for i = 1 to n where n = number of fields in table(Mapping)
'basically i want to do here is for i=1,Table=Table1 then for i=2, Table=Table2.is it possible?
Table= "Table"&i
Set rs = CurrentDatabase.OpenRecordset("Mapping")
Do While Not rs.EOF
strTableFields = strTableFields & rs!Table & ","
strTable2Fields = strTable2Fields & rs!OutputTable & ","
'so that that Table here is Table1 rather than a string "Table".
rs.MoveNext
Loop
rs.Close
'Remove the last comma.
strTable1Fields = Left(strTable1Fields, Len(strTable1Fields) - 1)
strTable2Fields = Left(strTable2Fields, Len(strTable2Fields) - 1)
strSQL = "INSERT INTO OutputTable (" & strOutputTableFields & ") SELECT " & strTableFields & " FROM Table " & i
db.Execute strSQL
Set rs = Nothing
Set db = Nothing
end for
i got the idea but i dont know how to write the code. Please help me, guys!
Hope to hear from you soon. Thanks
Last edited: