reset form to original state

Posted on 2010-03-28
Medium Priority
Last Modified: 2013-11-28
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:


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.  
Question by:JARichardHI
  • 2

Expert Comment

ID: 28943979
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.

Author Comment

ID: 28945594
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.  

Expert Comment

ID: 28990469
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

Accepted Solution

JARichardHI earned 0 total points
ID: 29024080

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.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Audit trails are very important in any system to hold people responsible for certain transactions and hold them to take ownership of their actions. This article is dedicated to all novice "Microsoft Access" developers.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question