Solved

First In First Out

Posted on 2009-07-03
12
294 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now