473,463 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loop Is Reading Empty After Filling

Hello,

So I finished my code but I have this one problem.

The Table That Is To Start The Loop Is Reading Empty.

Below is all the code to the program.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function Fill_Job_Positions()
  3.         'On Local Error GoTo Fill_Job_Positions_Err
  4.  
  5.     '-------------------------Summary--------------------------------
  6.     '
  7.     'Step 1:
  8.     '
  9.     '   Sets "dbs" as current Database of type "Data Acess Object"
  10.     '
  11.     '   Opens and Runs a Query that Makes a Table that may already exist.
  12.     '       Click "Yes" to delete existing table and paste to remake Table.
  13.     '
  14.     '   Opens a new recordset within the table "New Schedule"
  15.     '       For later usag3
  16.     '
  17.     '   Opens a new recordset within the table "Jobs Not Yet Filled"
  18.     '       For later usage
  19.     '
  20.     '-------------------------Summary--------------------------------
  21.  
  22.  
  23.     Dim dbs As DAO.Database
  24.     Set dbs = CurrentDb
  25.  
  26.     DoCmd.OpenQuery "Make Jobs To Fill Query", acViewNormal, acReadOnly
  27.  
  28.     DoCmd.OpenQuery "Put It Query - Replacing"
  29.  
  30.     Dim Replacements As DAO.Recordset
  31.     Set Replacements = dbs.OpenRecordset("Put It Query - Replacing")
  32.  
  33.     Dim Jobs As DAO.Recordset
  34.     Set Jobs = dbs.OpenRecordset("Jobs To Fill")
  35.  
  36.     Dim NotFilled As DAO.Recordset
  37.     Set NotFilled = dbs.OpenRecordset("Jobs Not Yet Filled")
  38.  
  39.     Dim RemainNF As DAO.Recordset
  40.     Set RemainNF = dbs.OpenRecordset("Jobs Remain Not Filled")
  41.  
  42.     Dim Schedule As DAO.Recordset
  43.     Set Schedule = dbs.OpenRecordset("New Schedule")
  44.  
  45.  
  46.     While Not Schedule.EOF
  47.  
  48.         'MsgBox "Schedule Record Before Deleting: " & Schedule![First Name]
  49.  
  50.         Schedule.Delete
  51.  
  52.         Schedule.MoveNext
  53.  
  54.     Wend
  55.  
  56.     While Not RemainNF.EOF
  57.  
  58.         'MsgBox "RemainNF Record Before Deleting: " & RemainNF![Main Positions]
  59.  
  60.         RemainNF.Delete
  61.  
  62.         RemainNF.MoveNext
  63.  
  64.     Wend
  65.  
  66.     While Not NotFilled.EOF
  67.  
  68.         'MsgBox "NotFilled Record Before Deleting: " & NotFilled![Main Positions]
  69.  
  70.         NotFilled.Delete
  71.  
  72.         NotFilled.MoveNext
  73.  
  74.     Wend
  75.  
  76.  
  77.     '-------------------------Summary--------------------------------
  78.     '
  79.     'Step 2:
  80.     '
  81.     '   Sets "dbs" as current Database of type "Data Acess Object"
  82.     '
  83.     '   Opens and Runs a Query that Makes a Table that may already exist.
  84.     '       Click "Yes" to delete existing table and paste to remake Table.
  85.     '
  86.     '   Creates a new table and names it "New Schedule"
  87.     '       For later usage
  88.     '
  89.     '-------------------------Summary--------------------------------
  90.  
  91.     'Testing the extraction method (fields from one table into another)
  92.     'Test ~ Copying Jobs (DAO) into NotFilled (DAO)
  93.  
  94.     'Declare the strings needed to individually extract data
  95.     Dim FirstName As String
  96.     Dim LastName As String
  97.     Dim JMP As String 'Jobs Main Positions
  98.     Dim RMP As String 'Replacements Main Positions
  99.     Dim Count As Integer 'Tracker for Jobs
  100.     Dim Count2 As Integer ' Tracker for Replacements
  101.     Count = 0
  102.  
  103.  
  104.     Jobs.MoveFirst
  105.  
  106.     While Not Jobs.EOF
  107.  
  108.         JMP = Jobs![Main Positions]
  109.  
  110.         Count2 = 0
  111.  
  112.         'MsgBox "Jobs Main Position Number: " & Count & " " & JMP
  113.  
  114.         Count = Count + 1
  115.  
  116.         While Not Replacements.EOF
  117.  
  118.             RMP = Replacements![Main Position]
  119.  
  120.             'MsgBox "Replacements Main Position Number: " & Count2 & " " & RMP
  121.  
  122.             If RMP = JMP Then
  123.  
  124.                 Schedule.AddNew
  125.  
  126.                 Schedule![First Name] = Replacements![First Name]
  127.  
  128.                 Schedule![Last Name] = Replacements![Last Name]
  129.  
  130.                 'In "Put It Query - Replacing" it is called "Main Position" because if references "Put It" the table
  131.                 Schedule![Main Positions] = Replacements![Main Position]
  132.  
  133.                 Schedule![Replacement Positions] = Replacements![Replacement Position]
  134.  
  135.                 Schedule.Update
  136.  
  137.                 'MsgBox "Count2 In First IF (before addition): " & Count2
  138.  
  139.                 Count2 = Count2 + 1
  140.  
  141.                 'MsgBox "Count2 In First IF (after addition): " & Count2
  142.  
  143.             End If
  144.  
  145.             Replacements.MoveNext
  146.  
  147.         Wend
  148.  
  149.         If Count2 = 0 Then
  150.  
  151.             'MsgBox "Count2 In Secound IF: " & Count2
  152.  
  153.             NotFilled.AddNew
  154.  
  155.             NotFilled![Main Positions] = Jobs![Main Positions]
  156.  
  157.             NotFilled.Update
  158.  
  159.             'MsgBox "Jobs in NotFilled Table: " & NotFilled![Main Positions]
  160.  
  161.         End If
  162.  
  163.         Replacements.MoveFirst
  164.  
  165.         Count = Count + 1
  166.  
  167.         Jobs.MoveNext
  168.  
  169.     Wend
  170.  
  171.     '----------------------------------------------------------------
  172.     'Not Compares Replacement Positions with Jobs Not Yet Filled
  173.     '----------------------------------------------------------------
  174.     Dim SRP As String 'Schedule Replacement Positions
  175.     Dim NFMP2 As String
  176.     Dim Count3 As Integer
  177.  
  178.     'MsgBox "Notfilled: " & NotFilled![Main Positions]
  179.  
  180.     While Not NotFilled.EOF
  181.  
  182.         Count3 = 0
  183.  
  184.         NFMP2 = NotFilled![Main Positions]
  185.         MsgBox "NFMP2: " & NFMP2
  186.  
  187.         While Not Schedule.EOF
  188.  
  189.             SRP = Schedule![Replacement Positions]
  190.             MsgBox "SRP: " & SRP
  191.  
  192.             If SRP = NFMP Then
  193.  
  194.                 Schedule![Scheduling Comments] = "Employee Needed For Both Of Their Positions"
  195.  
  196.                 Schedule.Update
  197.  
  198.                 MsgBox "Schedule![Scheduling Comments] = " & Schedule![Scheduling Comments]
  199.  
  200.                 MsgBox "Count3 (before add): " & Count3
  201.  
  202.                 Count3 = Count3 + 1
  203.  
  204.                 MsgBox "Count3 (after add): " & Count3
  205.  
  206.             End If
  207.  
  208.             Schedule.MoveNext
  209.  
  210.         Wend
  211.  
  212.         If Count3 = 0 Then
  213.  
  214.             MsgBox "There is no one to fill the following Position: " & NFMP
  215.  
  216.         End If
  217.  
  218.         NotFilled.MoveNext
  219.  
  220.     Wend
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228. End Function
  229.  
  230.  
  231.  
  232.  
Below is the code that I am having issues with.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  '----------------------------------------------------------------
  3.     'Not Compares Replacement Positions with Jobs Not Yet Filled
  4.     '----------------------------------------------------------------
  5.     Dim SRP As String 'Schedule Replacement Positions
  6.     Dim NFMP2 As String
  7.     Dim Count3 As Integer
  8.  
  9.     'MsgBox "Notfilled: " & NotFilled![Main Positions]
  10.  
  11.     While Not NotFilled.EOF
  12.  
  13.         Count3 = 0
  14.  
  15.         NFMP2 = NotFilled![Main Positions]
  16.         MsgBox "NFMP2: " & NFMP2
  17.  
  18.         While Not Schedule.EOF
  19.  
  20.             SRP = Schedule![Replacement Positions]
  21.             MsgBox "SRP: " & SRP
  22.  
  23.             If SRP = NFMP Then
  24.  
  25.                 Schedule![Scheduling Comments] = "Employee Needed For Both Of Their Positions"
  26.  
  27.                 Schedule.Update
  28.  
  29.                 MsgBox "Schedule![Scheduling Comments] = " & Schedule![Scheduling Comments]
  30.  
  31.                 MsgBox "Count3 (before add): " & Count3
  32.  
  33.                 Count3 = Count3 + 1
  34.  
  35.                 MsgBox "Count3 (after add): " & Count3
  36.  
  37.             End If
  38.  
  39.             Schedule.MoveNext
  40.  
  41.         Wend
  42.  
  43.         If Count3 = 0 Then
  44.  
  45.             MsgBox "There is no one to fill the following Position: " & NFMP
  46.  
  47.         End If
  48.  
  49.         NotFilled.MoveNext
  50.  
  51.     Wend
  52.  
  53.  
  54.  
  55. End Function
  56.  
  57.  
After running the module I go back to access and look within the "Jobs Not Yet Filled" table and it has 2 positions listed in which it should. What I don't understand is why the look in the above code does not go through.

I have tested it could with "msgbox" code and the While loop does not even enter through.

Thank you,

For Your Help
Jan 1 '11 #1
3 1425
ADezii
8,834 Expert 8TB
Before entering the Loop, try explicitly moving to the 1st Recordset in the Recordset, as in:
Expand|Select|Wrap|Line Numbers
  1. 'Code intentionally omitted...
  2. NotFilled.MoveFirst
  3. While Not NotFilled.EOF
  4. 'Code intentionally omitted...
Jan 2 '11 #2
Lysander
344 Expert 100+
Not sure what is going on, but between lines 23 and 27 of your code above, you have a

Schedule.Update

but no Schedule.addNew or Schedule.Edit.

Changing a record in Access requires 2 commands, not one.

Start with an rs.AddNew or rs.Edit

End with an rs.Update.

Hope this helps a little
Jan 2 '11 #3
Thank You Both!!

It worked and I understand why it didn't without the lines of code.

I hope you guys have a great year.

Thank You!
Jan 2 '11 #4

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

Similar topics

2
by: Satish Chimakurthi | last post by:
Hi all, This is in continuation of my email today regarding reading data files. I am stuck with one more problem now. Here are my two data files: a. fluid_grid.dat 1.00000000000000 ...
6
by: km | last post by:
Hi all, Why is it that the implementation of empty loop so slow in python when compared to perl ? #i did this in python (v 1.5) for x in xrange(1000): print x # this took 0.017 seconds...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
2
by: Claire | last post by:
This works ok in a new empty project. I write an empty string to a file. Looking at the file with a hex editor, there's a single byte of value zero. I expect this, it's utf8 encoding and this is...
3
by: vbnewbie | last post by:
I've been testing some of the example streamreads on 40 meg text file. I notice that it take awhile to read in debug.write and textbox1.text multi line. but if i use a textpad program, example...
9
by: Alex Buell | last post by:
I have a small text file which consist of the following data: ]] And the code I've written is as follows: ]] The trouble is, I can't work out why it goes into an infinite loop reading the...
1
by: Renster | last post by:
Folks, Im not sure if this would have been better going to this group, or a windows media one! Oh well... Im using fitnesse (for those that know it) to test an app that among other things can...
23
by: lisp9000 | last post by:
I wrote a small test program to read a file of data and print each line, but it's only printing the 2nd line out of 3 total lines. The test file, "foo.txt", has 3 lines: 7388: Zn->Z0 Run...
4
by: Shark | last post by:
Hi, I need a help. My application reads data from COM port, this data is then parsed and displyed on: 1. two plotters 2. text box. I'm using Invoke method to update UI when new data is...
1
by: edge691 | last post by:
Hello All, I'm just getting into programming, bit of a newbie. I'm having an issue with the streamreader. I had it working but I've changed something and it has stopped. I have it in a Do...
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.