June7, the way I understood your instruction was to replace ssafu looping code with yours, I could be wrong but this is what I did, please see the code I was testing database with.
Code:
Private Sub btnPjAdd_Click() 'Code modified by ssanfu
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim ControlPanel As String 'cboPJAdd
Dim Controller As Integer 'txtHtcAdd
Dim PhaseNumber As Integer 'txtPhaseNo
Dim PhaseLetterCount As Integer 'txtPhaseLetCnt
Dim Phase As String
Dim i As Integer, j As Long, k As Long 'counter
Set db = CurrentDb
Set rec = db.OpenRecordset("SELECT SkidNo, HTC, Phase, Notes FROM tbl_SkidAssignment")
k = 0 'counter
j = 1 'counter
'get values from form controls
ControlPanel = Me.cboPJAdd
Controller = Me.txthtcAdd
PhaseNumber = Me.txtPhaseNo
PhaseLetterCount = Me.txtPhaseLetCnt
'start loop
i = 1
Do While i <= Me.txthtcAdd
j = j + 1
For k = 1 To IIf(Me.txtPhaseNo = 1, 1, Me.txtPhaseLetCnt)
If i <= Me.txthtcAdd Then
' Debug.Print Choose(j, "A", "B", "C") & " : " & i
rec.AddNew
rec("SkidNo") = Me.cboPJAdd
rec("Htc") = i
rec("Phase") = Choose(j, "A", "B", "C")
rec.Update
End If
i = i + 1
Next
If j = IIf(Me.txtPhaseNo = 1, 1, 3) Then j = 0
Loop
'clean up
rec.Close
Set rec = Nothing
Set db = Nothing
MsgBox "Done"
DoCmd.OpenTable ("tbl_SkidAssignment")
End Sub
Originally Posted by
June7
When I test code, it starts loop with "A". Works perfect for me. Same for Phase of 1, only letter "A" is entered in records. Are you sure you are testing my code?
Really need to include code that verifies inputs are provided before creating records.
Why open table for users to view? Users should only work with forms and reports.
Don't bother with MsgBox if some other action is performed, such a opening table/form/report.