How to clear the values from a text box

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

How to clear the values from a text box

Post by davidcantor »

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.

User avatar
HansV
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

Post by HansV »

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

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: How to clear the vlaues from a text box

Post by davidcantor »

Me.txtEDate = rst.Fields("Date")
Me.txtDescription = rst.Fields("Desc")

I use these two fields from a recordset.

User avatar
HansV
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

Post by HansV »

But is there an If ... Then somewhere in the code?
Best wishes,
Hans

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: How to clear the vlaues from a text box

Post by davidcantor »

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.

User avatar
HansV
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

Post by HansV »

I'm afraid I don't have enough information to answer your question. Could you post the complete code?
Best wishes,
Hans

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: How to clear the vlaues from a text box

Post by davidcantor »

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

User avatar
HansV
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

Post by HansV »

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?
Best wishes,
Hans

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: How to clear the vlaues from a text box

Post by davidcantor »

no error message just the data for the previous record

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: How to clear the vlaues from a text box

Post by davidcantor »

i.e. the previous record that had values in the eDate and Description fields.

User avatar
HansV
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

Post by HansV »

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