473,395 Members | 1,931 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,395 software developers and data experts.

How to hide rows in a continuous form that have already been 'selected'?

137 100+
Situation:
I've got a main form, ScriptCreator, with two separate continuous sub-forms, ScriptCreatorSub and ScriptCreatorCurrentScript.

The idea is that the ScriptCreatorSub form displays all the options you can pick from, and each row has a 'Select' button next to it. When you click the Select button, the row of data is copied to a new table, called TestsForScripts, via an append query. This table is linked to the second continuous subform, ScriptCreatorCurrentScript. This second subform queries the table and pulls through any items already 'selected' concerning the current script.

So in short, you've got a form of options, and a form showing what you've already picked.

(Before anyone asks, I know that data duplication goes against database structure standards, but the use of the database and the manipulation of data after 'selection' means that data duplication is required, as opposed to just referencing the original table.)

All of this works fine, however what I'm now trying to implement a way of hiding/filtering out the items from the original list that have already been selected.

So for example say I've got Items A through to Z in ScriptCreatorSub. If I pick Item M, Item M appears in ScriptCreatorCurrentScript, and ScriptCreatorSub now only offers a list of Items A-L, N-Z.

I already have a system in place to filter the list on ScriptCreatorSub, which is based around the NeoPa's code example on this forum. I've tried adding in extra coding in the RunFilter process, but it just returns an error of:

Run-time error '2427':

You entered an expression that has no value.


This is the code I'm using for the filters, as I would have thought this is where I can apply new code to achieve what I'm after:

Expand|Select|Wrap|Line Numbers
  1. Private Sub RunFilter()
  2. Dim strFilter As String, strOldFilter As String
  3.  
  4. 'CheckFilter produces the new Filter depending on the values currently in
  5. 'the various filter boxes.
  6.  
  7.     strOldFilter = Me.Filter
  8.     'FilterRef_ID - Numeric
  9.     If Me!FilterRef_ID > "" Then _
  10.         strFilter = strFilter & _
  11.                     " AND ([Ref_ID]=" & _
  12.                     Me!FilterRef_ID & ")"
  13.     'FilterPageTitle - Text
  14.     If Me!FilterPageTitle > "" Then _
  15.         strFilter = strFilter & _
  16.                     " AND ([PageTitle] Like '*" & _
  17.                     Me!FilterPageTitle & "*')"
  18.     'FilterPageAddress - Text
  19.     If Me!FilterPageAddress > "" Then _
  20.         strFilter = strFilter & _
  21.                     " AND ([PageAddress] Like '*" & _
  22.                     Me!FilterPageAddress & "*')"
  23.     'FilterFieldElement - Text
  24.     If Me!FilterFieldElement > "" Then _
  25.         strFilter = strFilter & _
  26.                     " AND ([Field/Element] Like '*" & _
  27.                     Me!FilterFieldElement & "*')"
  28.     'FilterTestFor - Text
  29.     If Me!FilterTestFor > "" Then _
  30.         strFilter = strFilter & _
  31.                     " AND ([TestFor] Like '*" & _
  32.                     Me!FilterTestFor & "*')"
  33.     'FilterType - Text
  34.     If Me!FilterType > "" Then _
  35.         strFilter = strFilter & _
  36.                     " AND ([TypeOfTest] Like '" & _
  37.                     Me!FilterType & "*')"
  38.     'FilterPriority - Text
  39.     If Me!FilterPriority > "" Then _
  40.         strFilter = strFilter & _
  41.                     " AND ([Priority] Like '" & _
  42.                     Me!FilterPriority & "*')"
  43.         strFilter = strFilter & _
  44.                     " AND ([Ref_ID]<>" & _
  45.                     Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
  46.     'Debug.Print ".Filter = '" & strOldFilter & "' - ";
  47.     'Debug.Print "strFilter = '" & strFilter & " '"
  48.     'Tidy up results and apply IF NECESSARY
  49.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  50.     If strFilter <> strOldFilter Then
  51.         Me.Filter = strFilter
  52.     End If
  53.         Me.FilterOn = (strFilter > "")
  54. End Sub
  55.  
It's this part that I've added in the above code (near the bottom) which gives the error:

Expand|Select|Wrap|Line Numbers
  1.         strFilter = strFilter & _
  2.                     " AND ([Ref_ID]<>" & _
  3.                     Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
  4.  
If anyone can offer any help, it would be much appreciated! This forum has so far yet to fail on pointing out an obvious answer to my problems! :)

Thanks.
Jan 28 '11 #1

✓ answered by TheSmileyCoder

Hi Adam

Its obvious you've put alot of thought into both your work as well as your posts. Its very nice, and makes the discussing much easier and exact.

Duplicate vs Multiple records
Now, when I spoke of multiple records, I did not mean Duplicate records. As I understand it, if you add "A" and "H" to your second form, they exist as 2 records in some underlying table. As such there is multiple (non-duplicate) records relating to the primary record (your main form). For each (Bound) form (or subform) access ties a recordset. A recordset has a pointer sometimes called a bookmark, essentially saying which row/record the form is currently looking at. Even though its a continues form, it will only have 1 record in "focus", the pointer will only point to 1 record.

So when you reference:
Expand|Select|Wrap|Line Numbers
  1. Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
It will be the Ref_ID of the record currently pointed at. Access does not in such a case automatically handle that there are multiple records.


No records:
Im not 100% sure on this part, but I will write it as I believe it to be.
Now if your second form has no records and you use:
Expand|Select|Wrap|Line Numbers
  1. strFilter = strFilter & _
  2.                      " AND ([Ref_ID]<>" & _
  3.                      Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID] 
Your telling access you want all the records different from X, but your not telling access what X is, since X is a reference to something that does not exist. (The form has no record which to point at.)


Now lets turn to my code, which I should have explained better.

Expand|Select|Wrap|Line Numbers
  1. Private Function fStrListSelected() as String
  2.   'Create a list of the items selected
  3.      Dim rsClone as Dao.Recordset
  4.  
  5.   'Create a copy of the recordset used in the second form
  6.    set rsClone=Me.ScriptCreatorCurrentScript.RecordSetClone
  7.  
  8.   'Move to the last, then the first record, this is sometimes necessary for access to properly count the records.  
  9.     rsClone.MoveLast 'Not sure if these 2 lines are necessary
  10.     rsClone.MoveFirst
  11.  
  12.   'Count the records
  13.    if rsClone.RecordCount=0 then
  14.      'Nothing Selected Yet, so return an empty list
  15.        fStrListSelected=""
  16.    Else
  17.      'Loop through each record in the forms recordset
  18.      ' while recording the ref ID. 
  19.      ' Im assuming the Ref ID is the id of "A","B", and so on
  20.      Do While Not rsClone.Eof
  21.        'May have to replace , with ;, it depends on your regional settings
  22.        fStrListSelected=fStrListSelected & rsClone![Ref ID] & "," 
  23.        'Move to the next record
  24.        rsClone.MoveNext
  25.      Loop
  26.  
  27.      'There will be a trailing , remove it
  28.      fStrListSelected=left(fStrListSelected,len(fStrListSelected)-1)
  29.    End If
  30.    'Remove the copy from memory (cleanup)
  31.    set rsClone=Nothing
  32. End Function

EDIT: Ups, hit post by accident. Continuing:
If you have selected the records "A","B", and "C", and im gonna gues the ref ID of these is 1,2 and 3, then the function will return a string looking like "1,2,3". The second part of my original code, simply formats this into the SQL string. It would look like:
Expand|Select|Wrap|Line Numbers
  1. [Ref ID] Not In (1,2,3)
I hope I have managed to help more then I've confused. Im not always the best at explaining myself.

7 5386
beacon
579 512MB
Just on the surface, you have the left side of a parenthesis on line two in the last block of code (immediately after the word "AND"). Try removing that and see if it works.

Expand|Select|Wrap|Line Numbers
  1. " AND ([Ref_ID]<>" & _
  2. Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
  3.  
If it doesn't work, I'm sure I'll take a closer look.

Just so I understand, in case my suggestion doesn't work, does the user pick a letter from the alphabet and the subform filters the records for either the first half or the second half of the alphabet? So if I choose "K", I would get the records that fall between "A" and "M" on the subform, and if I choose "V", I would get the records that fall between "N" and "Z" on the subform?
Jan 29 '11 #2
Adam Tippelt
137 100+
Ah, don't know how that got parenthesis got left in there. Taking it out didn't seem to help though.

I think you've misinterpreted my example - probably my fault for trying to write it in short.
What I was trying to say was if I had a list of the following options:

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

If I selected option M, then this would be removed from the original list, and leave only the remaining options:

A, B, C, D, E, F, G, H, I, J, K, L, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

Then if I select another option, lets say option A, this is also then removed from the original list:

B, C, D, E, F, G, H, I, J, K, L, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

The code is supposed to query the current list and remove/hide any options that have already been selected. At the moment it just doesn't want to work.

Perhaps I'm putting the code in the wrong place, and should be putting it as a condition of the record source query?
Jan 31 '11 #3
Adam Tippelt
137 100+
I tried to add a where clause on the record source query with the code:

Expand|Select|Wrap|Line Numbers
  1. SELECT TestLibrary.Ref_ID, TestLibrary.PageTitle, TestLibrary.PageAddress, TestLibrary.[Field/Element], TestLibrary.TestFor, TestLibrary.Comments, TestLibrary.ExpectedResult, TestLibrary.TypeOfTest, TestLibrary.Company
  2. FROM TestLibrary
  3. WHERE (((TestLibrary.Ref_ID)<>[forms]![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
  4. ORDER BY TestLibrary.Ref_ID;
  5.  
But this made the continuous form populate as empty.

(I wasn't sure if "forms" was supposed to be in square brackets or not, but I tried both with and without, which resulted in the same outcome.)
Feb 1 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Hi Adam

Your code does not take into account that there can be multiple entries in your form, and neither does it take into account if nothing have been added.
Lets add in a function on your form, call it fStrListSelected()

Expand|Select|Wrap|Line Numbers
  1. Private Function fStrListSelected() as String
  2.   Dim rsClone as Dao.Recordset
  3.   set rsClone=Me.ScriptCreatorCurrentScript.RecordSetClone
  4.   rsClone.MoveLast 'Not sure if these 2 lines are necessary
  5.   rsClone.MoveFirst
  6.   if rsClone.RecordCount=0 then
  7.     'Nothing Selected Yet
  8.       fStrListSelected=""
  9.   Else
  10.     Do While Not rsClone.Eof
  11.       'May have to replace , with ;
  12.       fStrListSelected=fStrListSelected & rsClone![Ref ID] & "," 
  13.       rsClone.MoveNext
  14.     Loop
  15.     'There will be a trailing , remove it
  16.     fStrListSelected=left(fStrListSelected,len(fStrListSelected)-1)
  17.   End If
  18.   set rsClone=Nothing
  19. End Function

Now back in your main form, where you do the filtering:
Expand|Select|Wrap|Line Numbers
  1.   Dim strList as string
  2.   strList=fStrListSelected
  3.   If strList ="" then
  4.     'Nothing selected, no need to add to filter
  5.   Else
  6.     'Something is allready selected, filter it away
  7.     strFilter = strFilter & _ 
  8.                     " AND ([Ref_ID] Not In (" & strList & ") "
  9.   End If
I THINK this should work, I dont really have a good example at hand to try it on. The code is written straight, so it hasn't been tested. I hope you can work with it anyway.
Feb 1 '11 #5
Adam Tippelt
137 100+
Hi Smiley,

Your observations are true, however perhaps I need to explain why that is:

"Your code does not take into account that there can be multiple entries in your form"

The first form, with the original list, will never contain exact duplicates due to the Ref_ID being a primary key and therefore unique.
If you are referring to the second form, then you are quite right about it not taking duplicates into account. The whole point of what I've asked in this question is to tackle that area – prevent the user from creating duplicates in the first place. I’m trying to find a way from removing the item from the original list after its select button is pressed, so that the user does not have the option of having multiple entries of the same item. Once the Select Button next to the item is clicked, the item is added to the new list, and removed from the original (merely filtered out or hidden, not deleted). Therefore no duplicate entry can be created.
(Technically it wouldn’t be a duplicate anyway as these appended records now obtain a new primary key to keep them unique, but that isn’t visible to the user, and that isn’t the point.)

“and neither does it take into account if nothing have been added.”

I was under the impression that the functionality of it would work in the sense of `if it’s put into the second list, filter it out of the first. If it’s not in the second list, leave it in the first.’ If nothing has been added to the second list, then doesn’t that just mean that nothing matches the filter criteria and therefore nothing is filtered out?

With that in mind, is your suggested code still suitable?

Thank you all for your help and suggestions so far. Please forgive me if I’ve got it totally wrong - I’ve had to self teach myself both Access and VBA in the past couple of months and I’m just going on what seems logical.

Thanks.
Feb 1 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Hi Adam

Its obvious you've put alot of thought into both your work as well as your posts. Its very nice, and makes the discussing much easier and exact.

Duplicate vs Multiple records
Now, when I spoke of multiple records, I did not mean Duplicate records. As I understand it, if you add "A" and "H" to your second form, they exist as 2 records in some underlying table. As such there is multiple (non-duplicate) records relating to the primary record (your main form). For each (Bound) form (or subform) access ties a recordset. A recordset has a pointer sometimes called a bookmark, essentially saying which row/record the form is currently looking at. Even though its a continues form, it will only have 1 record in "focus", the pointer will only point to 1 record.

So when you reference:
Expand|Select|Wrap|Line Numbers
  1. Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID]
It will be the Ref_ID of the record currently pointed at. Access does not in such a case automatically handle that there are multiple records.


No records:
Im not 100% sure on this part, but I will write it as I believe it to be.
Now if your second form has no records and you use:
Expand|Select|Wrap|Line Numbers
  1. strFilter = strFilter & _
  2.                      " AND ([Ref_ID]<>" & _
  3.                      Forms![ScriptCreator]![ScriptCreatorCurrentScript]![Ref_ID] 
Your telling access you want all the records different from X, but your not telling access what X is, since X is a reference to something that does not exist. (The form has no record which to point at.)


Now lets turn to my code, which I should have explained better.

Expand|Select|Wrap|Line Numbers
  1. Private Function fStrListSelected() as String
  2.   'Create a list of the items selected
  3.      Dim rsClone as Dao.Recordset
  4.  
  5.   'Create a copy of the recordset used in the second form
  6.    set rsClone=Me.ScriptCreatorCurrentScript.RecordSetClone
  7.  
  8.   'Move to the last, then the first record, this is sometimes necessary for access to properly count the records.  
  9.     rsClone.MoveLast 'Not sure if these 2 lines are necessary
  10.     rsClone.MoveFirst
  11.  
  12.   'Count the records
  13.    if rsClone.RecordCount=0 then
  14.      'Nothing Selected Yet, so return an empty list
  15.        fStrListSelected=""
  16.    Else
  17.      'Loop through each record in the forms recordset
  18.      ' while recording the ref ID. 
  19.      ' Im assuming the Ref ID is the id of "A","B", and so on
  20.      Do While Not rsClone.Eof
  21.        'May have to replace , with ;, it depends on your regional settings
  22.        fStrListSelected=fStrListSelected & rsClone![Ref ID] & "," 
  23.        'Move to the next record
  24.        rsClone.MoveNext
  25.      Loop
  26.  
  27.      'There will be a trailing , remove it
  28.      fStrListSelected=left(fStrListSelected,len(fStrListSelected)-1)
  29.    End If
  30.    'Remove the copy from memory (cleanup)
  31.    set rsClone=Nothing
  32. End Function

EDIT: Ups, hit post by accident. Continuing:
If you have selected the records "A","B", and "C", and im gonna gues the ref ID of these is 1,2 and 3, then the function will return a string looking like "1,2,3". The second part of my original code, simply formats this into the SQL string. It would look like:
Expand|Select|Wrap|Line Numbers
  1. [Ref ID] Not In (1,2,3)
I hope I have managed to help more then I've confused. Im not always the best at explaining myself.
Feb 1 '11 #7
Adam Tippelt
137 100+
Hi Smiley,

Thanks for taking the time to explain in greater depth. You've explained very well and it makes more sense to me now. I shall give this a try and see if it works.

I think my problem was that my experience with other 'filters' has given the impression that Access does handle that there are multiple records and therefore I've got stuck in this idea that that's what I should be looking for. Perhaps as this is a slightly different circumstance, it requires a slightly different solution.


Thanks for all your help. I'll post if it works or not. :)
Feb 3 '11 #8

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

Similar topics

3
by: Prakash Wadhwani | last post by:
Is there any EASY way to highlight a full row in a continuous form so that as i navigate up & down the table/continuous form using the arrow keys, the entire line (all fields) get highlighted ? ...
1
by: Marcia | last post by:
I have a combobox for types of music and a combobox for artists. The rowsource query for the artists combobox associates artists with different types of music. In the query I use the name of the...
1
by: Mangini | last post by:
I have a continuous form wich contains all the rows of an invoice. Each row of the invoice is a record of a table rows. I would like to let the user insert a note(a comment) to a selected row. So...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
9
by: PeteCresswell | last post by:
I've got a continuous form that is a grid of statistical values. When the user clicks on a statistic, something happens (specifically a graph is created showing rolling one-year values for the...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
2
by: bobh | last post by:
Hi All, In Access97 I have a form setup as a continuous form several of the bound controls have calculations that are done in the 'after update' event via VBA code and all works fine. My...
3
by: S P Arif Sahari Wibowo | last post by:
Hi! I would like to make an editable continous form, where most fields will be from table A and editable, except 1-3 fields are a glimpse into table B and uneditable. Table A relate to table B...
1
by: tizmagik | last post by:
I have a combobox on a continuous form that has a recordsource that is set upon Form_Load event via VBA (based on initial form data and external form data entered). For data entry purposes the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
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...

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.