Happy Friday Everyone, So I was searching the web and came across some code that I would like to implement in a future project. So I made a test table in a new access database and started to play with it. I do not understand a few items and was hoping someone could help me out to get it to work and understand it. So below is the code and I can then explain what I understand and what I am confused on. If I can understand it and know how to use it that would be great.
So I understand the Const, recordset, SQL and the Integer. When I run the code it just adds the first account number 5 times. The table is set up as ID, acctnumber, custname. The account number is just 1, 2, 3, 4, and 5 and made up names like Donald Duck, Mickey Mouse and etc.
I am just trying to get the 5 tctacctnum to populate with 1, 2, 3, 4, and 5. Then my next step would be to add a WHERE clause and add the names associated to the account number.
So I do not understand the Next I and I tried RS.MoveNext and nada. So can anyone help with what I am doing wrong and am I even using the code correctly? Thanks
Code:
Option Compare Database
Const MaxAcctCount = 5
Const AcctTextBoxPrefix = "tctacctnum"
Private Sub cmdadd_Click()
Dim RS As DAO.Recordset, SQL As String
Dim I As Integer
For I = 1 to MaxAcctCount
SQL = *SELECT acctnumber FROM tbltest GROUP BY acctnumber"
SET RS = CurrentDb.OpenRecordset(SQL)
Me.Controls(AcctTextBoxPrefix & I).Value = RS!acctnumber
Next I
End Sub
So I understand the Const, recordset, SQL and the Integer. When I run the code it just adds the first account number 5 times. The table is set up as ID, acctnumber, custname. The account number is just 1, 2, 3, 4, and 5 and made up names like Donald Duck, Mickey Mouse and etc.
I am just trying to get the 5 tctacctnum to populate with 1, 2, 3, 4, and 5. Then my next step would be to add a WHERE clause and add the names associated to the account number.
So I do not understand the Next I and I tried RS.MoveNext and nada. So can anyone help with what I am doing wrong and am I even using the code correctly? Thanks