473,387 Members | 3,820 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,387 software developers and data experts.

Assign Next User Automatically based on Another Table

SueHopson
47 32bit
I have a table called Intake Staff with the following fields

ID
LastName
FirstName
Archive

For simplicity, lets say I have 3 records as shown below:
Expand|Select|Wrap|Line Numbers
  1. ID 1  LastName1  FirstName1  Archive = True
  2. ID 2  LastName2  FirstName2  Archive = False
  3. ID 3  LastName3  FirstName3  Archive = False
In my primary table called Tasks I also have a field called "Assigned To" which pulls from the Intake Staff table and displays only those records where Archive = False.
Expand|Select|Wrap|Line Numbers
  1. SELECT Contacts_Active.ID
  2.      , Contacts_Active.[Display As]
  3.      , Contacts_Active.Archive
  4. FROM   Contacts_Active
  5. WHERE  ((Contacts_Active.Archive)=False);
My question is, how can I set this field to automatically select a user to be assigned when a new record is opened, and then to start over at the top of the list when the last valid record is reached?
Jan 28 '20 #1
3 1865
NeoPa
32,556 Expert Mod 16PB
Let me start by suggesting you don't confuse an ID field with a sequencing one. It will often work that way if required but it isn't designed to so to rely on that is unwise.

Having said that you will need a sequencing field as well as a flag to indicate which record is next to be used. There may be some SQL that will do both jobs for you smoothly (IE. Clearing one record as well as setting the next.) but as Jet SQL has so many limitations that make a query non-updatable it's so much more straightforward to use recordset code in VBA to make the updates.

The Form Control would be set with a DefaultValue in the relevant Field (Your explanation talks of two tables but then gives an example of SQL referring to a table with a completely different name.) to match the value from the record with the flag set. This would be updated only after the record has actually been created though. You don't want to create gaps when a record is started but never saved.

The code would be something like :
Expand|Select|Wrap|Line Numbers
  1. Dim lngSequence As Long
  2. Dim strSQL As String
  3. Dim dbVar As DAO.Database
  4.  
  5. lngSequence = DLookup(Expr:="[SequenceField]" _
  6.                     , Domain:="[YourTable]" _
  7.                     , Criteria:="([NextFlag])")
  8. Set dbVar = CurrentDb()
  9. strSQL = Replace("SELECT   TOP 2%L" _
  10.                & "       , [SequenceField]%L" _
  11.                & "       , [NextFlag]%L" _
  12.                & "FROM     [YourTable]%L" _
  13.                & "WHERE    (Not [Archive])%L" _
  14.                & "  AND    ([SequenceField]>=%V)%L" _
  15.                & "ORDER BY [SequenceField]" _
  16.                , "%L", vbNewLine)
  17. strSQL = Replace(strSQL, "%V", lngSequence)
  18. With dbVar.OpenRecordset(Name:=strSQL, Type:=dbOpenDynaset)
  19.     Call .Edit
  20.     !NextFlag = False
  21.     Call .Update
  22.     Call .MoveNext
  23.     Call .Edit
  24.     !NextFlag = True
  25.     Call .Update
  26.     Call .Close
  27. End With
Jan 28 '20 #2
SueHopson
47 32bit
Thanks, I'll review more carefully tomorrow and try to apply the suggestions. Apologies for the late reply and truly appreciate the suggestion.
Feb 4 '20 #3
NeoPa
32,556 Expert Mod 16PB
Happy to help :-)

No need to apologise for lateness on a forum. It doesn't have to be very interactive. You just post with what's there at the time and move on to the next one.
Feb 5 '20 #4

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

Similar topics

2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
2
by: fkealty | last post by:
I'm attempting to make a small user database more efficient. I have an employee table with id numbers, last name first name title and address. Using a combo box I select the last name and have...
4
by: tarafinlay | last post by:
Hi all, I am new to access and am finding it a bit unintuitive having worked with SQL server in the past... And I am in a bit of a hurry because my employer wants me to crank something out which...
7
by: rcamarda | last post by:
I wish to build a table based on values from another table. I need to populate a table between two dates from another table. Using the START_DT and END_DT, create records between those dates. I...
3
by: colleen1980 | last post by:
Hi: Can any one please help me when user select 2 dates from DDLDate1 10/09/2006 and DDLDate2 10/12/06 and the name and it close the form. I need to create multiple records in the another table on...
0
by: acesfull | last post by:
Hi, I am trying to do something in SQL that I have done in PHP, but I am trying to have the operation performed as a stored procedure because of the sheer number of inserts I have to perform in PHP. ...
5
by: trixb | last post by:
Hello all, Here is what I need to do and need help with: I have a table that is feeding a chart in a report in Access. If this table has more than 50 records, the graph gets messy, and this is...
2
by: mgunnett | last post by:
Howdy, I have an Access 2007 database on a Win Vista x64 that is going to help me keep track of donations to my Clan. I currently have 3 Tables with the following Columns: User - UserID is unique...
12
by: tangara | last post by:
I have created a form where there's an option or 2 user types. All the data collected will be posted to my msaccess table. I have user java servlet to link the html to msaccess table so 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.