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

Can't Return back to starting value in rotation

I have created a rotation log for selecting wreckers, when i get to the last wrecker it will not return back to the first wrecker in the rotation, I am missing something any HELP?

Expand|Select|Wrap|Line Numbers
  1.   'Setup variables for holding unique id place holder
  2.  
  3.     Dim tsLastRecordID As Integer
  4.     Dim cfsLastRecordID As Integer
  5.     Dim wrckLastRecordID As Integer
  6.     Dim wrckFirstRecordID As Integer
  7.     Dim tsLstWreckerID
  8.     Dim cfsLstWreckerID
  9.  
  10.  
  11.     'First Get all the last record's on the table ID
  12.     'Getting Last Record I can check the columnd that contains the last used wrecker id
  13.  
  14.     tsLastRecordID = DMax("ID", "TS")
  15.     csfLastRecordID = DMax("ID", "CFS")
  16.     wrckLastRecordID = DMax("ID", "Wreckers")
  17.  
  18.     'If I don't get wrecker id I need the first one to get its name on the if statement...
  19.     wrckFirstRecordID = DMin("ID", "wreckers")
  20.  
  21.  
  22.     'Used the last ID from previous to get the WreckerID field..
  23.     tsLstWreckerID = DLookup("[WreckerID]", "TS", "[ID] = " & tsLastRecordID)
  24.     cfsLstWreckerID = DLookup("[WreckerID]", "CFS", "[ID] = " & csfLastRecordID)
  25.  
  26.     'Here we going to check what to display on the user screen
  27.     'If there hasnt been a previous wrecker id thenwe starting from the first wrecker..
  28.     If IsNull(tsLstWreckerID) And IsNull(cfsLstWreckerID) Then
  29.  
  30.         asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
  31.     ElseIf IsNull(cfsLstWreckerID) Then
  32.        If tsLstWreckerID = wrckLastRecordID Then
  33.          asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
  34.          Return 'Kills Operations
  35.        End If
  36.  
  37.        tsLstWreckerID = tsLstWreckerID + 1
  38.        asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & tsLstWreckerID)
  39.  
  40.     ElseIf IsNull(tsLstWreckerID) Then
  41.         If cfsLstWreckerID = wrckLastRecordID Then
  42.          asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
  43.          Return 'Kills Operations
  44.        End If
  45.  
  46.        cfsLstWreckerID = cfsLstWreckerID + 1
  47.        asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & cfsLstWreckerID)
  48.  
  49.     ElseIf tsLstWreckerID < cfsLstWreckerID Then
  50.  
  51.         'If the last wrecker equals the last of the list then go back to one..
  52.         If cfsLstWreckerID = wrckLastRecordID Then
  53.            asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
  54.            Return
  55.         End If
  56.  
  57.         cfsLstWreckerID = cfsLstWreckerID + 1
  58.         asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & cfsLstWreckerID)
  59.     ElseIf cfsLstWreckerID < tsLstWreckerID Then
  60.  
  61.         'If the last wrecker equals the last of the list then go back to one..
  62.         If tsLstWreckerID = wrckLastRecordID Then
  63.            asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
  64.            Return
  65.         End If
  66.         tsLstWreckerID = tsLstWreckerID + 1
  67.         asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & tsLstWreckerID)
  68.  
  69.     End If
Feb 17 '20 #1
3 2411
twinnyfo
3,653 Expert Mod 2GB
firecomm911,

I think you may have to provide us a bit more information. Help us to understand 1) exactly what it is that you are trying to do and 2) tell us about your tables and how they are related. Your code appears to be way more complicated than it might have to be, and the constant usage of Domain Aggregate functions is typically not a great approach--although there are times when they serve a useful purpose.

Standing by to hepp, if we can get some more useful information.
Feb 18 '20 #2
I have 3 tables that I am using TS, CFS, and Wreckers. Those tables have a relationship between the ID field in wrecker table and the AssignedWrecker field in CFS and TS. What I would like to do is assign a wrecker to either CFS or TS and the next time I open either table it show me next wrecker available to pick up a vehicle to make sure i am fair on giving work to those wreckers.

I hope this helps. sorry for not being to clear
Feb 18 '20 #3
NeoPa
32,556 Expert Mod 16PB
It seems like you need a conceptual understanding of the process.
  1. Start with a table of wreckers. We would typically suggest a name like [tblWrecker] but [Wreckers] can work if that's what you already have.
  2. [Wreckers] would need a PrimaryID field ([WreckerID] possibly.) as well as a separate field to indicate how many times it's been used. We'll name that [Usage] for now.
  3. You need to update the [Usage] every time you retrieve an item so I'd suggest that SQL is possibly not the best approach for this. Instead I'll show how a Function can do both tasks in one go (It returns a [WreckerID] (Long)).
  4. Expand|Select|Wrap|Line Numbers
    1. Public Sub NextWrecker() As Long
    2.     Dim strSQL As String
    3.     Dim dbVar As DAO.Database
    4.  
    5.     Set dbVar = CurrentDb()
    6.     strSQL = Replace("SELECT   *%L" _
    7.                    & "FROM     [Wreckers]%L" _
    8.                    & "ORDER BY [Usage]" _
    9.                    , "%L" vbNewLine)
    10.     With dbVar.OpenRecordset(Name:=strSQL, Type:=dbOpenDynaset)
    11.         NextWrecker = !WreckerID
    12.         Call .Edit
    13.         !Usage = !Usage + 1
    14.         Call .Update
    15.         Call .Close
    16.     End With
    17. End Function
  5. Call this function to return the next in your loop as well as to ensure it's been noted that this one has been used.

I hope that helps clarify the sort of process you should be looking at.
Apr 25 '20 #4

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

Similar topics

1
by: Evgeny Gopengauz | last post by:
For example, I have a table FORMULA_TABLE with the column FORMULA which contains some function y=f(x) in its symbol description like '@X*2+1' create table FORMULA_TABLE( ID int, FORMULA...
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
11
by: eros | last post by:
I use md5 function of PHP before storing the password in the database. Scenario: I put an password retrieval program. After authentication that the username is realy exist, send an email...
1
by: psycho | last post by:
How do we return a single value from a stored procedure. Suppose I have a stored procedure like this: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive...
2
by: Selva123 | last post by:
Hi All, Greetings. May be simple issue but your help sought. I am executing the system command like $res=system("notepad.exe"); thro a perl file named aa.pl. At command prompt - when I enter ...
0
Malathi
by: Malathi | last post by:
Hi, I created an exe through Console application that has 4 parameters as input.Im calling this exe in a windows application. After executing the exe, I want it to return a string(like"success"...
0
by: mylife smile | last post by:
Hi all, I have to return an integer value from vc++ to c# wcf. In vc++ the function works fine but in c# the function returns wrong integer value. In vc++ typedef struct { BOOL...
7
by: GeneH | last post by:
Hello, I am trying to requery a control on a main form from an AfterUpdate event of a control on a subform and then return back to the record and control at the subform. Instead i am returned to...
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: 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
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.