DO While Loop (1 Viewer)

Dina01

Registered User.
Local time
Today, 12:31
Joined
Apr 24, 2002
Messages
87
Hello

I am having some problems with my Do Until Loop......

My code is fine for everything else except I am confused on when to use Do While or Do Until.

What I want my form to do is that everytime the user clicks on the command button named "Btn_Ajouter"

I want him to get prompt withthe msgbos and make the procedure exceute...


Here is my code
**********************

Private Sub Btn_Ajouter_Click()

'Enable errors-handling routine
On Error GoTo Err_Btn_Ajouter_Click

Dim Temp As Variant ' Declares Temp as variant

'If Not IsNull(cboAgentAdd) Then

' Me.cboAgentAdd = ""
' Else

' Prompts user to save changes
Dim strMsg As String

strMsg = "AJOUTER OU METTRE UN AGENT EN ATTENTE."
strMsg = strMsg & "@Voulez vous ajouter ou mettre un agent en attente?"
strMsg = strMsg & "@Selectioner OUI pour ajouter ou NON pour le mettre en attente."

Do Until Btn_Ajouter_Click = True

If MsgBox(strMsg, vbQuestion + vbYesNo, "AJOUTER UN AGENT?") = vbYes Then

Me![txtDataID].Visible = True ' Make textbox visible
Me![txtDate].Visible = True ' Make cbobox visible
Me![cboAgentAdd].Visible = True ' Make textbox visible
Me![txtDebut].Visible = True ' Make cbobox visible
Me![txtCode].Visible = True ' Make textbox visible

Me![lblDataID].Visible = True ' Make textbox visible
Me![lblDate1].Visible = True ' Make cbobox visible
Me![lblAgentAdd].Visible = True ' Make textbox visible
Me![lblDebut].Visible = True ' Make cbobox visible
Me![lblCode].Visible = True ' Make textbox visible

' get previous data from record and save to temp variables
Temp = Me!DataID

'Takes info saved in Temp and enters it into DataID textbox
Me.txtDataID = Temp
' Set focus to DataID
Me.txtDataID.SetFocus

' Assign code level 1 to agent since he is getting assigned to the call
txtCode.Value = "1"
txtDate = Date
txtDebut = Time()

' Automatically drop down the Agent cbobox
DoCmd.GoToControl "cboAgentAdd"
Me.ActiveControl.Dropdown

Else

' get previous data from record and save to temp variables
Temp = Me!DataID

'Takes info saved in Temp and enters it into DataID textbox
Me.txtDataID = Temp
' Set focus to DataID
Me.txtDataID.SetFocus

' Assign code level 1 to agent since he is getting assigned to the call
txtCode.Value = "3"
txtDate = Now()
txtEnAttente = Time()


' Automatically drop down the Agent cbobox
DoCmd.GoToControl "cboAgentAdd"
Me.ActiveControl.Dropdown

End If
Loop
' End If
' Refresh the form
Me.Requery

Exit_Btn_Ajouter_Click:
Exit Sub

Err_Btn_Ajouter_Click:
MsgBox Err.description
Resume Exit_Btn_Ajouter_Click
End Sub


Private Sub cboAgentAdd_AfterUpdate()
'Enable errors-handling routine
On Error GoTo Err_cboAgentAdd_Click

Dim rsAgent As Recordset ' Set rs as recordset

' Set "Agent_tb" to be the current recordset
Set rsAgent = CurrentDb.OpenRecordset("Agent_tb")

With rsAgent
.AddNew
!DataID = Me.txtDataID
!Date = Me.txtDate
!HrsDebut = Me.txtDebut
!Agent = Me.cboAgentAdd
!Code = Me!txtCode
.Update
.Close
End With

' Set the recordset to null
Set rsAgent = Nothing

DataID.SetFocus

DoCmd.OpenQuery ("qryUpdAgtEffectifAdd")

Me![txtDataID].Visible = False ' Make textbox visible
Me![txtDate].Visible = False ' Make cbobox visible
Me![cboAgentAdd].Visible = False ' Make textbox visible
Me![txtDebut].Visible = False ' Make cbobox visible
Me![txtCode].Visible = False ' Make textbox visible

Me![lblDataID].Visible = False ' Make textbox visible
Me![lblDate1].Visible = False ' Make cbobox visible
Me![lblAgentAdd].Visible = False ' Make textbox visible
Me![lblDebut].Visible = False ' Make cbobox visible
Me![lblCode].Visible = False ' Make textbox visible

' Refresh the form
Me.Requery

' Exit to avoid handler
Exit_cboAgentAdd_Click:
Exit Sub

'Error handling routine
Err_cboAgentAdd_Click:

MsgBox Err.description
' Resume execution at same line that caused the error.
Resume Exit_cboAgentAdd_Click:

End Sub
 

AlanS

Registered User.
Local time
Today, 07:31
Joined
Mar 23, 2001
Messages
292
When you use the While clause, the loop is executed only as long as the condition remains true. When you use the Until clause, the loop is executed only as long as the condition remains false. In either case, execution of the loop stops when the value of the condition changes.

If you place the While or Until clause in the Do statement, the condition is evaluated before each iteration of the loop, which means that the loop may not execute at all. If you place it in the Loop statement, the condition is evaluated after each iteration of the loop, which means that the loop will always execute at least one iteration.
 

Users who are viewing this thread

Top Bottom