reset form to original state

This is pretty much what I need, but the how to clear the query portion wasn't there.

I have a:

Form:  frmAssetsMain
Subform (Datasheet): AllAssetsSubform

two text boxes on MainForm:

txt_username
txt_password

Upon entering an appropriate username and password into the respective boxes and hitting a Login button, the subform is populated based on those entries.  

I'm trying to create what I'm going to call btn_logout.

I'd like this button to not only clear the entries in the two text boxes but also set the subform back to its original state which is void of records.  
JARichardHIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SwordsowerCommented:
Put these in your btn_logout
frmAssetsMain.txt_username.Text = vbNullString
frmAssetsMain.txt_password.Text = vbNullString
That will take care of the 'clear out the data' portion.  Specifying the form when you are establishing the item (frmX.itemY.propertyZ) makes any form able to change values on any other form.
I'm not certain where your records are stored, but if you are storing things as strings, then you can set the value of the string to vbNullString and it will empty the textbox.  vbNullString only works for string values, trying to make an integer value set to vbNullString gives you a runtime error.
If you can give me some more information about your source (screenshots, perhaps?) I might be able to do more.
0
JARichardHIAuthor Commented:
Okay, clearing the txt_username and txt_password textboxes I ended up not needing because I simply added a

Me.txt_username = ""
Me.txt_Password = "" 

to the end of the onClick command for the login button.  So right after the user hits the login button and the datasheet subform populates the username and password fields are automatically cleared out.  So now its just a matter of clearing the records out of the datasheet subform.  This subform is currently bound to a query, and the records are stored in table Assets:

PARAMETERS [Forms]![frmAssetsMain]![thisHRNumber] Long;
SELECT Assets.HRNumber, Assets.uic, Assets.ItemName, Assets.SerialNumber, Assets.NSN, Assets.LIN, Assets.BuildingNumber, Assets.HRHolder, Assets.HRImage, Assets.HRDate, Assets.Comments, Assets.ID
FROM Assets
WHERE (((Assets.HRNumber) In (SELECT tbl_Relations.HRNumber FROM tbl_Relations WHERE (((tbl_Relations.ID)=[Forms]![frmAssetsMain]![thisHRNumber])))));
 
should it be another sort of query used to re-filter all the results in the subform to something which would find no records and thus make them all blank?

I've an extreme access coding novice and most of what I have now, coding wise, I've acquired from here.  
0
LeithauserCommented:
Me.txt_username = ""
Me.txt_Password = "" 
will clear the input. As for the subform, just unload it and reload it.
Unload AllAssetsSubform
Set AllAssetsSubform = Nothing
Load AllAssetsSubform
0
JARichardHIAuthor Commented:
Leithhauser,

Entered that code just as you have it into the private sub for btn_logout and received errors upon click "invalid use of property".  I actually ended up finding a solution by simply clearing the hidden text box thisHRNumber using Me!thisHRNumber = "" and then doing a Me!AllAssetsSubform.Requery.  which, since the thisHRNumber box is blank, which the original query is using to set the contents for the subform, then the subform simply requerys to a blank state.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.