How to clear the values from a text box
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
How to clear the values from a text box
I have a combo box and when an item is selected a textbox is populated with info relevant to the selection, however not all selection have this info, so when another selection is made that does not have the text box info I want the textbox to be blank. at the it still retains the info from the previous selection. the fields are not bound.
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: How to clear the vlaues from a text box
How do you populate the text box? Does it contain a formula starting with =, or do you use VBA code to fill the text box? If the latter, can you post the code?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
Re: How to clear the vlaues from a text box
Me.txtEDate = rst.Fields("Date")
Me.txtDescription = rst.Fields("Desc")
I use these two fields from a recordset.
Me.txtDescription = rst.Fields("Desc")
I use these two fields from a recordset.
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: How to clear the vlaues from a text box
But is there an If ... Then somewhere in the code?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
Re: How to clear the vlaues from a text box
no ifs, the rst is created based on two combo box selections and the two text boxes are populated with this recordset as shown above.
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: How to clear the vlaues from a text box
I'm afraid I don't have enough information to answer your question. Could you post the complete code?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
Re: How to clear the vlaues from a text box
Private Sub cmbEnrollmentDates_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM M_CaseInfo WHERE ClientID = " & Forms!frmMain!cmbName & " AND EDates = '" & Forms!frmMain!cmbEDates & "'")
Me.txtEDate.Visible = True
Me.lblEDate.Visible = True
Me.txtDescription.Visible = True
Me.lblDescription.Visible = True
Me.txtEDate = rst.Fields("EffectiveDate")
Me.txtDescription = rst.Fields("Desc")
Me.txtID = rst.Fields("ID")
Me.cmdAddExpense.Visible = True
End Sub
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM M_CaseInfo WHERE ClientID = " & Forms!frmMain!cmbName & " AND EDates = '" & Forms!frmMain!cmbEDates & "'")
Me.txtEDate.Visible = True
Me.lblEDate.Visible = True
Me.txtDescription.Visible = True
Me.lblDescription.Visible = True
Me.txtEDate = rst.Fields("EffectiveDate")
Me.txtDescription = rst.Fields("Desc")
Me.txtID = rst.Fields("ID")
Me.cmdAddExpense.Visible = True
End Sub
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: How to clear the vlaues from a text box
As far as I can tell, the value of txtEDate and of txtDescription is overwritten each time the user selects an item from the combo box. I don't see how the value associated with the previous selection can remain.
Or do you get an error message if there is no info for the new selection?
Or do you get an error message if there is no info for the new selection?
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
Re: How to clear the vlaues from a text box
no error message just the data for the previous record
-
- 3StarLounger
- Posts: 247
- Joined: 05 Nov 2012, 19:40
Re: How to clear the vlaues from a text box
i.e. the previous record that had values in the eDate and Description fields.
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: How to clear the vlaues from a text box
I'm afraid I can't explain that. Could you attach a stripped down and zipped copy of the database (don't include any sensitive information).
Best wishes,
Hans
Hans