Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Combobox when Error message closed 1

Status
Not open for further replies.

Tekhelpnet

Technical User
Oct 9, 2007
63
US
I want advise.
I wrote this

Private Sub Business_Unit_Click()
On Error GoTo ErrHandler

Me.BUSINESS_UNIT.Enabled = False

ErrHandler: (it is a wrong one but for example it works)
If Err = 2501 Then
' Report canceled - ignore this
Else
MsgBox Err.Description, vbExclamation
End If
End Sub

I am clicking OK to am error message and now I need combo box to get cleared. It would be perfect solution.
Yes and I also need correct error message. Thanks

 
What combo box? What would a correct error message be? You don't have a line to Exit the Sub so the error handling code will run every time.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Sorry I was not clear.
I have 2 combo boxes.
Report is to be printed for one value only.
When user selects the value in one and wants to select a value in another one - he is not suppose to be able to.
So OnClick I am writing an error message and I would LOVED if when used clicking OK to the message wrongly appeared value would be gone.
The rest I think I had fixed.
THANKS


Private Sub Business_Unit_Click()
On Error GoTo ErrHandler

Me.BUSINESS_UNIT.Enabled = False

ErrHandler:

MsgBox "Only one parameter allowed for this Report!", vbExclamation

End Sub
 
I am still confused however you can clear a combo box named "cboBusiness" with code like:
Code:
    Me.cboBusiness = Null

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Me.cboBusiness = Null ONLY IF another box is <> NULL...

OK here again.
I have a Form with 2 combo boxes. Report can be only run for 1 combo box value. So when user picks value in one combo box and leaves another empty - Report is running fine.
IF for some reason user picked value in one combo box and wants to pick in another - error message pops up that says 'Not available'...

I want to accomplish following: when I am clicking OK to the error message it should automatically clear that box.

If I insert "=NULL" it doesn't work...

Private Sub Business_Unit_Click()
On Error GoTo ErrHandler

Me.BUSINESS_UNIT.Enabled = False

ErrHandler: (it is a wrong one but for example it works)
If Err = 2501 Then
' Report canceled - ignore this
Else
MsgBox Err.Description, vbExclamation
End If

Me.BUSINESS_UNIT.Enabled = NULL - DOESN"T CLEAR THE BOX!

End Sub

Thanks

P.S.
I could also written it so the second box is not available to pick value IF first value picked already.
I am not sure on wich event though...
 
I'm not sure where you got this line from :-(
Code:
    Me.BUSINESS_UNIT.Enabled = NULL

I would use code in the after update event of combo box cboOne that would see if cboOne is null or not and set the value of combo box [cboTwo] accordingly.

You can't set an Enabled property to anything other than True or False.

After update of cboOne
Code:
If Not IsNull(Me.cboOne) Then
   Me.cboTwo = Null
End If

After update of cboTwo
Code:
If Not IsNull(Me.cboTwo) Then
   Me.cboOne = Null
End If

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
OK, I solved it.
Please, comment if can be improved!

Private Sub Recruiter_ID_Name2_AfterUpdate()

If IsNull(Me.BUSINESS_UNIT) Then
Me.Recruiter_ID_Name2.Enabled = True

Else
MsgBox "Only one parameter allowed for this Report!", vbExclamation
Me.Recruiter_ID_Name2 = Null


End If

End Sub



Private Sub Business_Unit_AfterUpdate()

If IsNull(Me.Recruiter_ID_Name2) Then
Me.BUSINESS_UNIT.Enabled = True


Else

MsgBox "Only one parameter allowed for this Report!", vbExclamation
Me.BUSINESS_UNIT = Null
End If

End Sub
 
I don't know why you are messing around with enabling the controls when it seems you are never disabling a control. Plus, you have code to enable Recruiter_ID_Name2 in the after update of Recruiter_ID_Name2. You are enabling a control that already must be enabled. This is like unlocking the car door immediately after you got in the car. I would leave everything enabled.

Assuming the user wants to keep the most recent update of either combo box:
Code:
Private Sub Recruiter_ID_Name2_AfterUpdate()
    If IsNull(Me.BUSINESS_UNIT) Then
      'nothing to do
     Else
      MsgBox "Only one parameter allowed for this Report!", vbExclamation
      Me.BUSINESS_UNIT = Null
    End If
End Sub


Private Sub Business_Unit_AfterUpdate()
 If IsNull(Me.Recruiter_ID_Name2) Then
   'nothing to do
  Else
   MsgBox "Only one parameter allowed for this Report!", vbExclamation
   Me.Recruiter_ID_Name2 = Null
 End If  
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top