473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

filter on new record

Hello I have an "add new" button on a form. I would like the button to go to a new record AND filter the form on that new record. The form also has an unbound combo box used to look for and filter to existing records. My code for the "add new" button OnClick Event so far (below) removes any existing filter, and goes to a new record, but I would like to have the form filter so only the new record is shown.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddBldg_Click()
  2. On Error GoTo Err_btnAddBldg_Click
  3.  
  4. If Me.FilterOn = True Then
  5.     Me.FilterOn = False
  6.     End If
  7.  
  8.     DoCmd.GoToRecord , , acNewRec
  9.  
  10. Exit_btnAddBldg_Click:
  11.     Exit Sub
  12.  
  13. Err_btnAddBldg_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_btnAddBldg_Click
  16.  
  17. End Sub
  18.  
I tried adding Me.FilterOn = True after the DoCmd, but this did not work - the form returned to the previous filter.
Any help would be greatly appreciated!
Bridget
Oct 31 '07 #1
5 5378
Hello I have an "add new" button on a form. I would like the button to go to a new record AND filter the form on that new record. The form also has an unbound combo box used to look for and filter to existing records. My code for the "add new" button OnClick Event so far (below) removes any existing filter, and goes to a new record, but I would like to have the form filter so only the new record is shown.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddBldg_Click()
  2. On Error GoTo Err_btnAddBldg_Click
  3.  
  4. If Me.FilterOn = True Then
  5.     Me.FilterOn = False
  6.     End If
  7.  
  8.     DoCmd.GoToRecord , , acNewRec
  9.  
  10. Exit_btnAddBldg_Click:
  11.     Exit Sub
  12.  
  13. Err_btnAddBldg_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_btnAddBldg_Click
  16.  
  17. End Sub
  18.  
I tried adding Me.FilterOn = True after the DoCmd, but this did not work - the form returned to the previous filter.
Any help would be greatly appreciated!
Bridget
One additional thing...
I tried using "DoCmd.ApplyFilter" as below, but got "syntax error (missing operator) in query expression '[BldgID] = '."
Bridget

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddBldg_Click()
  2. On Error GoTo Err_btnAddBldg_Click
  3.   Dim strSQL As String
  4.  
  5. If Me.FilterOn = True Then
  6.     Me.FilterOn = False
  7.     End If
  8.  
  9.     DoCmd.GoToRecord , , acNewRec
  10.  
  11.   strSQL = "[BldgID] = " & Me![txtBldgID]
  12.  
  13.   DoCmd.ApplyFilter wherecondition:=strSQL
  14.  
  15. Exit_btnAddBldg_Click:
  16.     Exit Sub
  17.  
  18. Err_btnAddBldg_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_btnAddBldg_Click
  21.  
  22. End Sub
  23.  
Oct 31 '07 #2
FishVal
2,653 Expert 2GB
Hi, Bridget.

Form has a special property for that - DataEntry. When set to True in design view or via VBA code it allows user to enter new record only, the rest records are invisible.
Oct 31 '07 #3
Hi, Bridget.

Form has a special property for that - DataEntry. When set to True in design view or via VBA code it allows user to enter new record only, the rest records are invisible.
Hi FishVal,
Wow -- such a quick response! thank you. I set Data Entry to "yes" in my form and now when my form opens, it opens to a new record, which is great. However, I would also like to set Data Entry to true / yes when clicking the "Add New" button on the form when its already open. Do you have any pointers on code to make this happen?

Thanks again!
Bridget
Oct 31 '07 #4
Hi FishVal,
Wow -- such a quick response! thank you. I set Data Entry to "yes" in my form and now when my form opens, it opens to a new record, which is great. However, I would also like to set Data Entry to true / yes when clicking the "Add New" button on the form when its already open. Do you have any pointers on code to make this happen?

Thanks again!
Bridget
OK, I replied before playing enough with it. After the DoCmd I added a Me.DataEntry line of code as below:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
  2. Me.DataEntry = true
  3.  
and it seems to work well!

Thanks again,
Bridget
Oct 31 '07 #5
FishVal
2,653 Expert 2GB
You are welcome, Bridget.

Best regards,
Fish
Oct 31 '07 #6

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

Similar topics

11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
2
by: Salad | last post by:
I have a log file with a list of records. The log file can be unfiltered or filtered. I have a command button to call a data entry form from the log. At first I was only going to present the...
3
by: Tony Williams | last post by:
Sorry to repost but I cannot work this out. Can anyone come up with a suggestion? I have a main form based on Table1. The form has a tab control of three pages. Each page has a subform based on a...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
4
by: bgreer5050 | last post by:
I have a form with various fields with a double click event to bring up a filter via a query. Is it possible to goto another field and apply another filter only to the records that were found...
3
by: birt | last post by:
I know I am getting in my own way .... so someone please save me from myself! I created a form and rather than force the users to scroll through all the records to find theirs I decided to have...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.