473,624 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clear form button and the code to make it work

11 New Member
I am using a form to sort a report, but I can't seem to get the "clear form" button to work. I used the wizard when I installed the button, using the clear form option under the form option list. What I want to be able to do is clear the information on the drop down combo box in case I want to change the sort order. This is what the code looks like now:

Option Compare Database

Expand|Select|Wrap|Line Numbers
  1. Private Sub close_Click()
  2. On Error GoTo Err_close_Click
  3.  
  4.  
  5.     DoCmd.close
  6.  
  7. Exit_close_Click:
  8.     Exit Sub
  9.  
  10. Err_close_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_close_Click
  13.  
  14. End Sub
  15.  
  16. Private Sub cmdSetSort_Click()
  17.  
  18.     Dim strSQL As String, intCounter As Integer
  19.     'Build strSQL String
  20.     For intCounter = 1 To 4
  21.         If Me("cboSort" & intCounter) <> "" Then
  22.         strSQL = strSQL & "[" & Me("cboSort" & intCounter) & "]"
  23.         If Me("Chk" & intCounter) = True Then
  24.             strSQL = strSQL & " DESC"
  25.         End If
  26.         strSQL = strSQL & ", "
  27.     End If
  28.     Next
  29.  
  30.     If strSQL <> "" Then
  31.         'Strip Last Comma & Space
  32.         strSQL = Left(strSQL, (Len(strSQL) - 2))
  33.         'Set the OrderBy property
  34.         Reports![rptPersonnel].OrderBy = strSQL
  35.         Reports![rptPersonnel].OrderByOn = True
  36.     Else
  37.         Reports![rptPersonnel].OrderByOn = False
  38.  
  39.     End If
  40.  
  41. End Sub
  42.  
  43.  
  44. Private Sub Form_Open(Cancel As Integer)
  45. ' Open the report maximized, in Print Preview
  46.     DoCmd.OpenReport "rptPersonnel", acViewPreview
  47.     DoCmd.Maximize
  48. End Sub
  49.  
  50. Private Sub Refresh_Click()
  51. On Error GoTo Err_Refresh_Click
  52.  
  53.  
  54.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  55.  
  56. Exit_Refresh_Click:
  57.     Exit Sub
  58.  
  59. Err_Refresh_Click:
  60.     MsgBox Err.Description
  61.     Resume Exit_Refresh_Click
  62.  
  63. End Sub
Not sure what I'm doing wrong, but I would appreciate some help. Also attached is a picture of what my sort box looks like.
Attached Images
File Type: gif combobox.gif (4.6 KB, 773 views)
Feb 11 '08 #1
1 5699
joshapalooza
11 New Member
I am using a form to sort a report, but I can't seem to get the "clear form" button to work. I used the wizard when I installed the button, using the clear form option under the form option list. What I want to be able to do is clear the information on the drop down combo box in case I want to change the sort order. This is what the code looks like now:

Option Compare Database

Expand|Select|Wrap|Line Numbers
  1. Private Sub close_Click()
  2. On Error GoTo Err_close_Click
  3.  
  4.  
  5.     DoCmd.close
  6.  
  7. Exit_close_Click:
  8.     Exit Sub
  9.  
  10. Err_close_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_close_Click
  13.  
  14. End Sub
  15.  
  16. Private Sub cmdSetSort_Click()
  17.  
  18.     Dim strSQL As String, intCounter As Integer
  19.     'Build strSQL String
  20.     For intCounter = 1 To 4
  21.         If Me("cboSort" & intCounter) <> "" Then
  22.         strSQL = strSQL & "[" & Me("cboSort" & intCounter) & "]"
  23.         If Me("Chk" & intCounter) = True Then
  24.             strSQL = strSQL & " DESC"
  25.         End If
  26.         strSQL = strSQL & ", "
  27.     End If
  28.     Next
  29.  
  30.     If strSQL <> "" Then
  31.         'Strip Last Comma & Space
  32.         strSQL = Left(strSQL, (Len(strSQL) - 2))
  33.         'Set the OrderBy property
  34.         Reports![rptPersonnel].OrderBy = strSQL
  35.         Reports![rptPersonnel].OrderByOn = True
  36.     Else
  37.         Reports![rptPersonnel].OrderByOn = False
  38.  
  39.     End If
  40.  
  41. End Sub
  42.  
  43.  
  44. Private Sub Form_Open(Cancel As Integer)
  45. ' Open the report maximized, in Print Preview
  46.     DoCmd.OpenReport "rptPersonnel", acViewPreview
  47.     DoCmd.Maximize
  48. End Sub
  49.  
  50. Private Sub Refresh_Click()
  51. On Error GoTo Err_Refresh_Click
  52.  
  53.  
  54.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  55.  
  56. Exit_Refresh_Click:
  57.     Exit Sub
  58.  
  59. Err_Refresh_Click:
  60.     MsgBox Err.Description
  61.     Resume Exit_Refresh_Click
  62.  
  63. End Sub
Not sure what I'm doing wrong, but I would appreciate some help. Also attached is a picture of what my sort box looks like.
Never mind, I figured out the answer by myself. For those that are interested about the answer though, here is what I figured out:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  2. On Error Resume Next
  3. Me.cboSort1 = ""
  4. Me.cbosort2 = ""
  5. Me.cboSort3 = ""
  6. Me.cboSort4 = ""
  7. cboSort1.SetFocus
  8. End Sub
Hope this helps those of us out there that are still trying to puzzle their way through VBA and Access.
Feb 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3049
by: Max Harvey | last post by:
Hi, I made up a nice little form which had its own sub form in it. I made a litle VB code so that when I pressed a button it would move form the form (frmConference) to the subform (frmBookingBookingBased), start a new record, and copy some values form the form into some fields in the subform, and then leave the cursor sitting (in focus) at the begining of the subform.
15
4652
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
21
5192
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each table and 11 sub items with data about each column. When a Row in ListView1 is selected the Data in ListVies2 is loaded to show the correct data. Initially the first row in ListView1 is selected in FormX load
0
2865
by: Cleako | last post by:
Here is my dilema. I have a validation summary that I use soley for my Required Field Validators. I have it setup to run from a Page.Validate call in the code-behind, this is because I need to be able to clear text or other various functions need to be checked before it hits the back side. That works fine if I do things that way up to a point, if by chance the validation summary says "Date field required" then I edit the date and...
0
4830
by: Flack | last post by:
I have pasted at the end of this message a small sample program I whipped up to do some testing. It's a form with a datagrid and two buttons. Each button clears the dataTable that is the source of the dataGrid, and then adds five rows. Button2 is the same as button1 just that it does this in a different thread (I was testing if I was having some threading issues). Anyway, it seems that the location of the call to dt.Rows.Clear()...
0
1174
by: dpierson | last post by:
I have just converted one of my applications from .Net 1.1 / VS2003 to ..Net 2.0 / VS2005. I'm now seeing some different behavior in my app. Here's a simple case description: Form 1: Stock form with MainMenu and one MenuItem (menuItem1) which has several sub-MenuItems of its own. IsMdiContainer = true. Has a button (button1).
5
5784
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is pressed it removes the check but does not re-hide the submit <div> bit. The way i see it, I have 3 options: 1) To simply remove the clear for button. 2) To exclude the said checkbox from the CLEAR button function. 3) To have the CLEAR button run...
1
2280
by: johnacooke | last post by:
I have a HTML form that is generated in part by PHP. The action attribute on the form tag calls itself, so that I can validate the fields without using any other form of code like Javascript to validate fields, etc. All works well; fields like e-mail addresses are correctly validated with one notable exception. The <input type="reset" ... only works the first time the form is called.
5
4498
by: karsagarwal | last post by:
I have a bounded form and after I click the button to update/save. THe fields are still there. Is there a way to clear off the fields in the bounded form. Thanks, SA Here's the code that I have: Private Sub cmdSave_Click()
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.