473,403 Members | 2,222 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,403 software developers and data experts.

FindNext for multiple criteria not working

6
I am trying to use the .FindNext (and .FindPrevious) function on an update form "next button" to find the record that meets certain criteria.
Expand|Select|Wrap|Line Numbers
  1. Private Sub NextRecord_Click()
  2. Dim foundmatch As Boolean
  3.  
  4. For x = 0 To 3 Step 1
  5.   With Me.RecordsetClone
  6.     .FindNext "[Sensitivity] = " & [TempVars]![AccessLevel] + x
  7.     If .NoMatch Then
  8.         foundmatch = False
  9.     Else
  10.         Me.Bookmark = .Bookmark
  11.         foundmatch = True
  12.         Exit For
  13.     End If
  14.   End With
  15. Next
  16. If foundmatch = False Then
  17.     MsgBox "No More Records"
  18. End If
  19.  
  20. End Sub
  21.  
Upon a user entering the database the users accesslevel is assigned to a temp variable (1 to 4), and each project has a sensitivity rating of 1 to 4. The code below was used and worked for both next and previous only in finding records when the sensitivity and accesslevel were equal but not for sensitivities below the users access level which they are qualified to see.
Expand|Select|Wrap|Line Numbers
  1. Private Sub PrevRecord_Click()
  2. Dim Stringy As String
  3. Stringy = "[Sensitivity] = " & [txtaccess]
  4. With Me.RecordsetClone
  5. .FindPrevious Stringy
  6. If .NoMatch Then
  7. MsgBox "No More Records"
  8. Else
  9. Me.Bookmark = .Bookmark
  10. End If
  11. End With
  12. End Sub
  13.  
Note: The form is pulled from a query with Sensitivity one of the fields, and [txtaccess] is a text box on the field with the default value set at [TempVars]![AccessLevel]. I've also tried changing it to:
Expand|Select|Wrap|Line Numbers
  1. Stringy = "[Sensitivity] >= " & [txtaccess]
  2.  
but that doesn't work either
Mar 17 '16 #1

✓ answered by jforbes

I would rethink this approach. Even after you get this to work, you will probably find some other place that you will need to apply a Band-Aid fix, then you will find another, and another.

Storing the Access Level into a TempVar or a Global Variable is a good idea. I would change the Form to use a Filter so that only the records at the user's access level are displayed and then let MS-Access manage the Navigation between records.

Applying this filter is pretty easy and there are a few different methods, but one of the most straight forward is to include the filter in the DoCmd.OpenForm Statement. You could use some code similar to the following for the button that opens up your Form:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "SomeForm", , , "[Sensitivity]=" & TempVars("AccessLevel").Value
Again, this is the easy way. You could base the Form's RecordSource on a Query that uses the AccessLevel to limit the records.

If you don't want to mess with that (although, I highly recommend you do), you might get your code working if you flip your sign in your where clause:
Expand|Select|Wrap|Line Numbers
  1. Stringy = "[Sensitivity] <= " & [txtaccess]

5 2450
jforbes
1,107 Expert 1GB
I would rethink this approach. Even after you get this to work, you will probably find some other place that you will need to apply a Band-Aid fix, then you will find another, and another.

Storing the Access Level into a TempVar or a Global Variable is a good idea. I would change the Form to use a Filter so that only the records at the user's access level are displayed and then let MS-Access manage the Navigation between records.

Applying this filter is pretty easy and there are a few different methods, but one of the most straight forward is to include the filter in the DoCmd.OpenForm Statement. You could use some code similar to the following for the button that opens up your Form:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "SomeForm", , , "[Sensitivity]=" & TempVars("AccessLevel").Value
Again, this is the easy way. You could base the Form's RecordSource on a Query that uses the AccessLevel to limit the records.

If you don't want to mess with that (although, I highly recommend you do), you might get your code working if you flip your sign in your where clause:
Expand|Select|Wrap|Line Numbers
  1. Stringy = "[Sensitivity] <= " & [txtaccess]
Mar 17 '16 #2
madg
6
I already had a filter so that it would open to the selected project record which worked. I am able to get both filters to work independently however, not at the same time.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ProjectID_Click()
  2.  
  3. Dim stCriteria As String
  4. Dim stCriteria1 As String
  5. Dim stCriteria2 As String
  6.  
  7. stCriteria1 = "[ProjectID]=" & [ProjectID]
  8. stCriteria2 = "[Sensitivity] >= " & [TempVars]![AccessLevel]
  9. stCriteria = stCriteria1 & " And " & stCriteria2
  10.  
  11. DoCmd.OpenForm "Project Update", , , stCriteria
  12.  
  13.  
  14. End Sub
  15.  
Mar 17 '16 #3
jforbes
1,107 Expert 1GB
I'm a little unsure what you are attempting to do with ProjectID_Click().

There are a few typical scenarios when opening a Form:
  1. Opening the Form to add a New Record. No existing Records are available in the Form other than the records that are being added while the Form is open.
  2. Opening a Form to a specific Record so it can be Edited. Only the Record to be edited is available in the Form and there is no navigation other than closing the Form. stCriteria1 = "[ProjectID]=" & [ProjectID] is typical criteria for this type of operation.
  3. When Browsing Records, all the Records are available and the can be navigated at will. Sometimes the NewRecord is available to add Records, but that mostly depends on how tightly the New Record creation is controlled. stCriteria2 = "[Sensitivity] >= " & [TempVars]![AccessLevel] is typical criteria for this type of operation.

So, in your code, when these two pieces of Critera are ANDed together, the user will get scenario 2, Editing a single record, and that is only if they have the AccessLevel to view to the Record.

You may need two separate buttons, one for Editing and one for Browsing. Or maybe define what you are attempting to do a little more and we can get it hashed out.
Mar 18 '16 #4
madg
6
Ideally I would like the user to open an "Update Project" pop-up form after double clicking from a "Project List" datasheet form. I would then also like them to browse through to update an other project that they have access to, in the case they want to make multiple updates.
Mar 21 '16 #5
madg
6
I was able to solve the problem by using a combobox that updates the form instead. That way I just put a where condition on the query for the access level and it works perfectly now!
Mar 21 '16 #6

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

Similar topics

4
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("",...
3
by: developing | last post by:
Hello How do I specify multiple criteria for FindFirst or FindRecord (or anything else) that takes the criteria from a form. (text field and number field) edit: this will be in the after...
4
by: JHNielson | last post by:
I have a query that I'm trying to update with a dlookup with multiple criteria This is the string: EVNT_DT: DLookUp("","","( .EVNT_QTR=.) & (.=.)") When i run it it says it can't find the...
1
by: 2D Rick | last post by:
I want to open a report using OpenReport and passing it a Where Clause with multiple criteria. I know the Where Clause below is way off but it conveys what I need. Dates are of string type. ...
0
by: ChadK | last post by:
I am trying to open a report based on what the user selects on a form. Each individual criteria works but when I try to combine to pass multiple criteria it doesn't. I have read what I can find on...
1
by: akirekab | last post by:
I am using DCount, but I am not able to find how to set simple multiple criteria. Here is sample of what i need. =DCount("PatientProfileID","qryFaceToFaceReason_EAP_VG","FaceToFaceReasonID=2"...
3
by: kstevens | last post by:
Please help. I know the sysntax is wrong. Here are some details. I am looking for the sum of past shipped items. I originally wrote this Dsum with only one criteria, but because of multiple...
1
by: Brendan Wolf | last post by:
Happy Halloween all, I have been struggling at work with a DLookup using multiple criteria. I would like a text box to display the results of a DLookup based on the values selected in three...
3
by: Brendan Wolf | last post by:
Happy Halloween all, I have been struggling at work with a DLookup using multiple criteria. I would like a text box to display the results of a DLookup based on the values selected in three...
4
by: DANNYOCEAN | last post by:
I have a code that sucessfully calculates how many numbers are lower than for example 45 , for large sample number list. But i´m looking for a code that have a COUNT function with MULTIPLE...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.