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. -
Private Sub btnAddBldg_Click()
-
On Error GoTo Err_btnAddBldg_Click
-
-
If Me.FilterOn = True Then
-
Me.FilterOn = False
-
End If
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Exit_btnAddBldg_Click:
-
Exit Sub
-
-
Err_btnAddBldg_Click:
-
MsgBox Err.Description
-
Resume Exit_btnAddBldg_Click
-
-
End Sub
-
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
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. -
Private Sub btnAddBldg_Click()
-
On Error GoTo Err_btnAddBldg_Click
-
-
If Me.FilterOn = True Then
-
Me.FilterOn = False
-
End If
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Exit_btnAddBldg_Click:
-
Exit Sub
-
-
Err_btnAddBldg_Click:
-
MsgBox Err.Description
-
Resume Exit_btnAddBldg_Click
-
-
End Sub
-
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 -
Private Sub btnAddBldg_Click()
-
On Error GoTo Err_btnAddBldg_Click
-
Dim strSQL As String
-
-
If Me.FilterOn = True Then
-
Me.FilterOn = False
-
End If
-
-
DoCmd.GoToRecord , , acNewRec
-
-
strSQL = "[BldgID] = " & Me![txtBldgID]
-
-
DoCmd.ApplyFilter wherecondition:=strSQL
-
-
Exit_btnAddBldg_Click:
-
Exit Sub
-
-
Err_btnAddBldg_Click:
-
MsgBox Err.Description
-
Resume Exit_btnAddBldg_Click
-
-
End Sub
-
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, 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
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: -
DoCmd.GoToRecord , , acNewRec
-
Me.DataEntry = true
-
and it seems to work well!
Thanks again,
Bridget
You are welcome, Bridget.
Best regards,
Fish
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |