Solved

First In First Out

Posted on 2009-07-03
12
296 Views
Last Modified: 2013-11-27
Good Day All

I am trying to create a FIFO (First In First Out) with a combo box in MS Access 2003.  When you select a name in a combo box that name automatically rotates to the bottom of the list in the combo box.  Does anyone have examples of coding on First In First Out, or suggest how this could be created?

Thanks
0
Comment
Question by:Beeyen
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 24772738
If you have a table of two columns, ID and Namefield you initially number them in the sequence you want them to appear in the combo.
So you rowsource orders then emtries by this field.

Then when you select a value from the combo, you run an update query to update that record in the source table, so that the ID is Max(id) +1.  Then requery the combo.

You could use an autonumber field as the id instead.  In that case you would append a new record with the name value and then delete the existing record.  
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 24772753
You would have an extra column on your names table like Lineup.

You make the query for your combo box
-------------------------------------
SELECT EmpName
FROM EmpTable
ORDER BY Lineup
-------------------------------------

Then your on click event would be something like
-------------------------------------
On_Click
'Do whatever else

Dim LineNum As String
DIM SQL as string

LineNum = DMax("Lineup", "EmpTable") + 1

SQL = "UPDATE EmpTable " & _
     "SET Lineup = " & LineNum " " & _
     "WHERE EmpName = '" & Me.ComboBox.Value & "'"

DOCMD.setwarnings false
docmd.runsql sql
DOCMD.setwarnings true
-------------------------------------
0
 
LVL 84
ID: 24772786
How are you filling this box now?

How are you ordering the names in this box now?

What happens to the other names in the box after you select a name? In other words, if I have this list:

Blue
Red
Green
Yellow

and I select "Green", what would the list look like afterward? What if I select Red?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Beeyen
ID: 24772897
Good Day jimpen:

Thank you for the quick response.

Ok, below is the property of the combo box I would like to make FIFO, could you suggest how I would set it up to get started?  


Control Source = ProductionAssigned
Name = Productionassignedname
Combo Box
Row Source Type: Table/Query
Row Source:
SELECT tblBenefitsEmployee.EmployeeID, tblBenefitsEmployee.LastName & ", " & [FirstName] AS Expr1 FROM tblBenefitsEmployee ORDER BY tblBenefitsEmployee.LastName & ", " & [FirstName], tblBenefitsEmployee.FirstName WITH OWNERACCESS OPTION;

Bound Column: 1
Column Count: 2
Column Widths: 0;2;2
0
 
LVL 2

Expert Comment

by:sirtam
ID: 24772926
Hi.

Make a new module for the FIFO and insert the following code.

It is a simple FIFO used with Strings, but can be changed to be used with whatever you want.
Option Compare Database
Option Explicit
 
'
' A FIFO (First In First Out) buffer.
'
Private vData As New Collection
    'vData = New Collection
 
'
'  Adds an item to the FIFO
'
Public Sub Push(v As String)
   If vData.count = 0 Then
      vData.Add v
   Else
      vData.Add v, , , vData.count
   End If
End Sub
 
'
'  Clears all items from the FIFO
'
Public Sub Clear()
   Set vData = New Collection
End Sub
 
'
' Returns the number of items in the FIFO
'
Public Property Get count() As Integer
   count = vData.count
End Property
 
 
 
'
'  Returns an item from the FIFO
'
Public Function Pop() As String
   If vData.count = 0 Then
      Pop = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Pop = vData(1)
      Else
         Pop = vData(1)
      End If
      vData.Remove 1
   End If
End Function
 
'
'  Returns the next item in the FIFO but does
'  not remove it from the FIFO
'
Public Function Peek() As String
   If vData.count = 0 Then
      Peek = Null
   Else
      If VarType(vData(1)) = vbObject Then
         Peek = vData(1)
      Else
         Peek = vData(1)
      End If
   End If
End Function

Open in new window

0
 
LVL 2

Expert Comment

by:sirtam
ID: 24772947
Note: This code is taken (but a bit edited) from the following thread:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_10067783.html
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 24773062
You would have to still add the Lineup (or whatever column) to the tblBenefitsEmployee. But from there it would look something like this.

I assume that you have a button that does the actual assignment or whatever else.

SELECT tblBenefitsEmployee.EmployeeID, tblBenefitsEmployee.LastName & ", " & [FirstName] AS Expr1 FROM tblBenefitsEmployee ORDER BY tblBenefitsEmployee.LastName & ", " & [FirstName], tblBenefitsEmployee.FirstName
ORDER BY Lineup
 WITH OWNERACCESS OPTION;
-------------------------------------------
 
On_Click
'Do whatever else
 
Dim LineNum As String
DIM SQL as string
 
LineNum = DMax("Lineup", "tblBenefitsEmployee") + 1
 
SQL = "UPDATE tblBenefitsEmployee " & _
     "SET Lineup = " & LineNum " " & _
     "WHERE EmployeeID= '" & Me.Productionassignedname.Value & "'"
 
DOCMD.setwarnings false
docmd.runsql sql
DOCMD.setwarnings true
 
Me.Productionassignedname.Requery
 
End Sub

Open in new window

0
 
LVL 44

Expert Comment

by:GRayL
ID: 24774080
Maybe I'm naive, but what's this got to do with FIFO?
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 24774122
From what I can tell -- the next employee in line gets the next job.

So when he hits the drop down list in the combo box, the next employee in the list gets the job. Then the next one gets the next and so on. He's wanting to avoid slamming one person multiple times.

It might not be true FIFO, but more of get an ordered cycle down.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 24852160
Just wondering if you have done anything with this?
0
 

Author Comment

by:Beeyen
ID: 24917676
Good Day Mr Jimpen

I apoligize for the delay, I was called out of town on an emergency and have restarted my project.  I have reviewed your suggestion which is what I am trying to accomplish.  I will give your coding suggestion a try and let you know the if I have further questions, if not I will just accept this as the solution.

Thanks
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 25616581
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question