473,473 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

trouble with next button on a filtered form

AccessIdiot
493 Contributor
Anyone getting sick of me yet? :D

I have a button on my form that opens a new form but with a filter:
Expand|Select|Wrap|Line Numbers
  1.     stDocName = "frm_Specimen_Entrainment"
  2.     stLinkCriteria = "[Entrainment_ID]=" & Me![Entrainment_ID]
  3.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  4.  
This works really well except that, as expected, I can't add new records. Interestingly, you can click the "next record" button and it will show a blank form (and then grey out) but the Entrainment_ID goes blank and the record doesn't get saved.

If I change the above code and pass the Entrainment_ID as OpenArgs then I can add a new record. However, I can keep hitting the next button as many times as I want and it keeps adding new records, whether I have actual data in there or not.

I am looking for something in between - the next button goes to a new record, then greys out so I can't keep adding new records until someone hits the "add new record" button.

Is this possible?

Thanks!
Apr 26 '07 #1
22 2050
Rabbit
12,516 Recognized Expert Moderator MVP
Anyone getting sick of me yet? :D

I have a button on my form that opens a new form but with a filter:
Expand|Select|Wrap|Line Numbers
  1.     stDocName = "frm_Specimen_Entrainment"
  2.     stLinkCriteria = "[Entrainment_ID]=" & Me![Entrainment_ID]
  3.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  4.  
This works really well except that, as expected, I can't add new records. Interestingly, you can click the "next record" button and it will show a blank form (and then grey out) but the Entrainment_ID goes blank and the record doesn't get saved.

If I change the above code and pass the Entrainment_ID as OpenArgs then I can add a new record. However, I can keep hitting the next button as many times as I want and it keeps adding new records, whether I have actual data in there or not.

I am looking for something in between - the next button goes to a new record, then greys out so I can't keep adding new records until someone hits the "add new record" button.

Is this possible?

Thanks!
Opening the form with the stLinkCriteria filter shouldn't prevent you from adding records.
Apr 26 '07 #2
AccessIdiot
493 Contributor
One would think! And yet that Entrainment_ID isn't getting populated on the new record.
Apr 26 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
One would think! And yet that Entrainment_ID isn't getting populated on the new record.
It shouldn't, a filter doesn't limit what goes into a field.
Isn't that why you passed the Entrainment_ID in OpenArgs as well? So that you can assign it as the Entrainment_ID for new records? But of course that's also the reason why it keeps adding new records. Assigning it an entrainment_id saves it as a new record with just that one field.

What you could do is on form close, run a delete SQL that deletes all records where only the entrainment_id has data in it.
Apr 26 '07 #4
AccessIdiot
493 Contributor
Cool. I didn't realize that's what was happening. I figured once the correct Entrainment_ID was passed through the filter then one could keep going with that same Entrainment_ID.

How does one specify in the delete clause records that only contain the ID field? Do you have to cycle through all the controls and look for blanks?

thanks again for the help Rabbit. :)
Apr 26 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Cool. I didn't realize that's what was happening. I figured once the correct Entrainment_ID was passed through the filter then one could keep going with that same Entrainment_ID.

How does one specify in the delete clause records that only contain the ID field? Do you have to cycle through all the controls and look for blanks?

thanks again for the help Rabbit. :)
Not a problem.

It's not as easy as looking for records that only have info in the ID field. Rather you have to find records where the required fields are blank. Something along the lines of:
Expand|Select|Wrap|Line Numbers
  1. DELETE FROM tbl_Name
  2. WHERE Field1 Is Null AND Field2 Is Null AND Field3 Is Null;
Apr 26 '07 #6
AccessIdiot
493 Contributor
Yuck - there are lots of controls, and a subform to boot.

Pardon my ignorance but how do I create a SQL query in the On Close event? Can I do it in the VBA or do I create a macro or . . . ?
Apr 26 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Yuck - there are lots of controls, and a subform to boot.

Pardon my ignorance but how do I create a SQL query in the On Close event? Can I do it in the VBA or do I create a macro or . . . ?
You don't have to check every control, just enough of them to be sure that it was an accidental click of the create new record button.

But I doubt anyone's going to go on a clicking spree creating a bunch of mostly empty records.

There are two ways to do a query in VBA. One is to create the actual query in query design that does what you want. Then you open the query in VBA using.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "Query Name"
Or you can build the string yourself in VBA
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE FROM ..."
Apr 26 '07 #8
AccessIdiot
493 Contributor
Ahh, DoCmd.RunSQL is what I was looking for. :)
Apr 26 '07 #9
AccessIdiot
493 Contributor
Hmmm, I must be doing something wrong. I get the pop up that says I"m about to delete 0 records from my table. Do I need to have the table name in front of each field name? My code right now is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.     DoCmd.RunSQL "DELETE FROM tbl_Specimen_Replicate WHERE Species_ID Is Null AND Gender_ID Is Null AND Lifestage_ID Is Null AND Disp_Capture_ID Is Null AND Disp_Release_ID Is Null AND Anomalies Is Null AND Comments Is Null;"
  3. End Sub
Maybe I need
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.     DoCmd.RunSQL "DELETE FROM tbl_Specimen_Replicate WHERE tbl_Specimen_Replicate.Species_ID Is Null AND tbl_Specimen_Replicate.Gender_ID Is Null AND tbl_Specimen_Replicate.Lifestage_ID Is Null . . . etc"
  3. End Sub
?
Apr 26 '07 #10
Rabbit
12,516 Recognized Expert Moderator MVP
Hmmm, I must be doing something wrong. I get the pop up that says I"m about to delete 0 records from my table. Do I need to have the table name in front of each field name? My code right now is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.     DoCmd.RunSQL "DELETE FROM tbl_Specimen_Replicate WHERE Species_ID Is Null AND Gender_ID Is Null AND Lifestage_ID Is Null AND Disp_Capture_ID Is Null AND Disp_Release_ID Is Null AND Anomalies Is Null AND Comments Is Null;"
  3. End Sub
Maybe I need
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.     DoCmd.RunSQL "DELETE FROM tbl_Specimen_Replicate WHERE tbl_Specimen_Replicate.Species_ID Is Null AND tbl_Specimen_Replicate.Gender_ID Is Null AND tbl_Specimen_Replicate.Lifestage_ID Is Null . . . etc"
  3. End Sub
?
You don't need to put the the table name in front of each one. Are all those fields really going to be null? If it's an autonumber then it won't be null. If it has a default value, then it won't be null. You might have to adjust the criteria depending on the field. If it's a subform and is linked by a field, then those key values get filled in automatically by the form and won't be null.

So open up the table and take a look at the accidental records and see what's being automatically filled even though all you did was click New Record.
Apr 26 '07 #11
AccessIdiot
493 Contributor
There is one field that has a default value but I didn't list it in the code. I only chose fields that could be left totally blank.

All the fields that end with "_ID" are combo boxes though and are foreign keys. Does that make a difference? I can't just use "Comments" and "Anomalies" which are text boxes because it is likely that they will be empty even if the rest of the info is filled out.
Apr 26 '07 #12
Rabbit
12,516 Recognized Expert Moderator MVP
Go to design view and make a select query that pulls all the correct records then convert it to a delete query and look at the SQL.

Sometimes when I have trouble with a SQL statement I use the query design to get it to return the correct records and then look at how the SQL is set up.
Apr 26 '07 #13
AccessIdiot
493 Contributor
Ahhh, excellent suggestion. I should have seen what I was doing wrong - I forgot to specify the fields in the beginning of the Delete clause! Should be
Delete Field1, Field2, Field3
From table
Where Field1 Is Null AND Field2 Is Null AND Field3 Is Null.

Access DID put the table name in front of everything but I'm not sure that's totally necessary. So the full query looks like this:
Expand|Select|Wrap|Line Numbers
  1. DELETE tbl_Specimen_Entrainment.Anomalies, tbl_Specimen_Entrainment.Comments, tbl_Specimen_Entrainment.Species_ID, tbl_Specimen_Entrainment.Gender_ID, tbl_Specimen_Entrainment.Lifestage_ID, tbl_Specimen_Entrainment.Disp_Capture_ID, tbl_Specimen_Entrainment.Disp_Release_ID
  2. FROM tbl_Specimen_Entrainment
  3. WHERE (((tbl_Specimen_Entrainment.Anomalies) Is Null) AND ((tbl_Specimen_Entrainment.Comments) Is Null) AND ((tbl_Specimen_Entrainment.Species_ID) Is Null) AND ((tbl_Specimen_Entrainment.Gender_ID) Is Null) AND ((tbl_Specimen_Entrainment.Lifestage_ID) Is Null) AND ((tbl_Specimen_Entrainment.Disp_Capture_ID) Is Null) AND ((tbl_Specimen_Entrainment.Disp_Release_ID) Is Null));
  4.  
Thanks again Rabbit! You are on it today! :)
Apr 26 '07 #14
Rabbit
12,516 Recognized Expert Moderator MVP
Sorry, I forgot you needed that.

No, you don't need to put the table name in front and you probably don't need all those parentheses.

You might want to change that first listing of fields to just DELETE * FROM because a listing of fields will only empty those fields rather than delete the records. At least that's what I'm assuming.
Apr 26 '07 #15
AccessIdiot
493 Contributor
I tried running it from the Query window and it seemed to work. I'll give your version a whirl too though as it seems a lot cleaner and easier to read.
Apr 26 '07 #16
Rabbit
12,516 Recognized Expert Moderator MVP
I tried running it from the Query window and it seemed to work. I'll give your version a whirl too though as it seems a lot cleaner and easier to read.
After you run it from the query window did you check the table?
Apr 26 '07 #17
AccessIdiot
493 Contributor
Yes and it worked great so I'm just going to go with it.

A related question though (so I'm not starting a new thread yet) - the message "you are about to delete one record" is going to scare the pants off the users. Can I either hide that message or create a custom one? I tried to follow the tutorial for creating custom error messages done by ADezii but it's a bit beyond me.
Apr 26 '07 #18
Rabbit
12,516 Recognized Expert Moderator MVP
You can hide that with:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. SQL stuff
  3. DoCmd.SetWarnings True
Apr 26 '07 #19
AccessIdiot
493 Contributor
Obviously silly but just making sure question - by sql stuff you mean put the DoCmd before and after my Delete statement? :)
Apr 26 '07 #20
AccessIdiot
493 Contributor
Yep, works great, thanks again! Wow, i'm getting so much done today with your help! :D
Apr 26 '07 #21
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem.
Apr 26 '07 #22
NeoPa
32,556 Recognized Expert Moderator MVP
Obviously silly but just making sure question - by sql stuff you mean put the DoCmd before and after my Delete statement? :)
Notice that the DoCmd line before the SQL statement(s) is different from the one after them.
May 3 '07 #23

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

Similar topics

8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
3
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
8
by: Rabel | last post by:
I am new to asp and I am having a little trouble with the Request.form option. What I want to do is I have a dropdown box. <select name="selecter" class="text" id="selecter"> <option...
0
by: Ironr4ge | last post by:
Hi everyone, By the rate its going it want be long till I start growing gray hair... but anyway.. to come to the point... I am trying to open the form "Languages" with a diffrent record...
2
by: bhipwell via AccessMonster.com | last post by:
I need to put a button that allows the user to move to the next record. On the form, I have a list of employees that are filtered by the company they work for. Obviously, if I use the simple...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
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,...
1
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...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.