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
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