Clearing txt fields

rgreene

Registered User.
Local time
Today, 03:22
Joined
Jan 22, 2002
Messages
168
I'm working on a program for checking in and out books for our companys library.
I have a couple check boxes for whether or not the book is in or out.
when you click the check out button the check box automatically changes to out and todays date is entered in the out date field (ODATE)(Date/Time field) and the due date field (DDATE))(Date/Time field) is today +14 days. There is also a field for the employees name (EMPLOYEENAME) (TEXT field)for who is checking out the book. Department (DEPARTMENT) (Also a txt field). and a few others . This part is working fine. My problem is when the book gets checked back in. I have a button for check in that changes the status to IN and clears the ODATE, DDATE, and a few others. That part works fine. But it won't clear the EMPLOYEENAME and DEPARTMENT (TEXT) fields. here is the code I have:
Private Sub CheckIn_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmCheckout"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Me.In = True

If Me.In = True Then
Me.Out = False
Me.ODate = Null
Me.DDate = Null
Me.EmployeeName = Null
Me.Department = Null


Refresh
End If

When I start typing the me.out a box appears with the different options I can put in after the me. however the EmployeeName and Department isn't listed as an option.

I hope I haven't confused you too much.

Thanks,
Rick
 
Try this...

for the employee name and department textboxes, try the following lines instead of what you have:

-------
Me!EmployeeName.setfocus
Me!EmployeeName.text = ""

Me!Department.setfocus
Me!Department.text = ""
-------

That will work for other textboxes you're trying to clear as well...

Edit: I just realized you said the EmployeeName and Department textboxes were not showing up in the intellipopupthingy. Make sure those two textbox controls are are actually called "EmployeeName" and "Department". Also make sure that you're writing this code within the proper form, otherwise you're refering to the wrong "Me".

Sam
 
Last edited:
No Go

Thanks dsmaj but I'm still having a problem. I'm getting Microsoft Access can't find the field "Name" refered to in your expression. (my mistake it is called Name not EmployeeName) if I rem that out I get the same thing for "Department". I know the names are correct. Again if I go to type the command in in event procedure I do me.department.setfocus and when I get to the Department it isn't listed as a possible field (if that makes sense).

I think you might have found my problem I just read your edit. I've got a command button that I click on and it changes my in/out check box then opens up a different form. and then I try to clear the fields. Here is the entire code:
Private Sub Checkin_Click()
On Error GoTo Err_Checkin_Click

Dim stDocName As String
Dim stLinkCriteria As String

Me.In = True
Me.Out = False

stDocName = "frmCheckout"
stLinkCriteria = "[BookID]=" & Me![Book ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


Me!Name.SetFocus
Me!Name.Text = ""
Me!Department.SetFocus
Me!Department.Text = ""
Me!Email.SetFocus
Me!Email.Text = ""

Me.ODate = Null
Me.DDate = Null
Refresh


Exit_Checkin_Click:
Exit Sub

Err_Checkin_Click:
MsgBox Err.Description
Resume Exit_Checkin_Click

End Sub

Thanks and I'm going to start using "Intellipopupthingy" if that's OK!!!!
 
Last edited:
Pat: would a Forms!frm_MyForm!txtWhatever.Value = "" clear the value that is currently displayed on the form? I've had trouble with that lately, and that's why I've been just setting the control's focus and updating the Text property...but if it's better to update the displayed value via .value, I should figure out why I'm having trouble with it.

Sam
 
Yeah, I know "" != NULL, and also that you can't assign a zero-length string to a numeric field...I can't remember exactly what error I was getting, but I think it may have been unrelated, because I just tried doing it again on a fresh form and it seems to work.

Here's a quick question for you though: How would you go about checking whether a text box is empty or not (for the purposes of checking that all required fields have been filled in)? I was having a terrible time doing this and ended up settling on:

if isnull(Me!txtBox.value) then
' ...
end if

However, I imagine that if a user entered some info, and then erased it (thus giving the textbox a value of "" and not NULL), it would be allowed. Short of further checking for a value of "", what is a cleaner way of doing this?

Sam
 

Users who are viewing this thread

Back
Top Bottom