473,399 Members | 2,159 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,399 software developers and data experts.

Function Module looping problem

I'm running Access 97 and my modules are looping if someone puts an
invalid value in.

The setup:
3 macros - get_clock_num, verify_clocknum, append_to_history
3 functions. each in their own module - get_clocks(), verify_clocks(),
append()

Each macro runs a function from in its corresponding module.
Here is my code.
From the "gatheremp_num" module... ________________________________________
Public Loader, Packer As String

Function get_clocks()

Packer = ""
Loader = ""

Packer = InputBox("Input packer")
Loader = InputBox("Input loader")

DoCmd.RunMacro "verify_clocknum"

End Function
_______________________________________

From the "verify" module... _______________________________________
'Verify if the Loader and Packer are clocked in using the
"look_up_empid" query

Function verify_clocks()
Dim packname, loadname As String
Dim packcount, loadcount As String
Dim lookup_emp_id As QueryDef
MsgBox "Step0"

'count the number of times each employee shows up. If null, ask for
names again
packcount = DCount("[clocknum]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadcount = DCount("[clocknum]", "look_up_empid", "[clocknum]= '" &
Loader & "'")

If packcount = 0 Then
MsgBox "step1"
MsgBox "One or more employees not clocked in. Rescan badges"
DoCmd.RunMacro "get_clock_num"
Else
MsgBox "Step2"
GoTo Verify_Loader
End If

Verify_Loader:
MsgBox "step3"
If loadcount = 1 Then
MsgBox "step4"
GoTo Display_Results
Else
MsgBox "Step5"
MsgBox "One or more employees not clocked in. Rescan badges"
DoCmd.RunMacro "get_clock_num"
End If

Display_Results:

'Lookup employee names from loader and packer input boxes
packname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Loader & "'")

'display employee names
MsgBox ("Packer is " & packname & " " & Packer & Chr(13) & "Loader is "
& loadname & " " & Loader)

DoCmd.RunMacro "append_to_history"

End Function
_________________________________________

From the "append_history" module...

____________________________________________

Function append()

Dim SQLstr, SQLstr2, packname, loadname, order, machno As String
Dim curdate As Date
Dim look_up_empid, getorder As QueryDef
Dim history, outputtable As TableDef

' gets variables from queries
packname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Packer & "'")
loadname = DLookup("[empname]", "look_up_empid", "[clocknum]= '" &
Loader & "'")
order = DFirst("[ordno]", "getorder")
machno = DFirst("[mach num]", "getorder")

'declares append query to put values into history table

SQLstr = "INSERT INTO history (clockno,empname,ordno,curdate,machno)
VALUES" & _
"('" & Packer & "','" & packname & "','" & order & "',#" &
Now() & "#,'" & machno & "')"

SQLstr2 = "INSERT INTO history (clockno, empname,ordno,curdate,machno)
VALUES" & _
"('" & Loader & "','" & loadname & "','" & order & "',#" &
Now() & "#,'" & machno & "')"

'executes queries
MsgBox "step6"
DoCmd.RunSQL SQLstr
MsgBox "step7"
DoCmd.RunSQL SQLstr2

End Function
_________________________________________
I know this is alot of code and I apologize for that but I'm really
stuck and it makes no sense to me.

This code runs perfectly if I put valid 2 numbers into Packer and
Loader. Here is the steps that run when 2 good numbers are entered.
Step 0,2,3,4,6,7

Here is what happens if I put a bad number and good number.
Step 0,1
It asks again so I put in 2 good numbers
Step 0,2,3,4,6,7,3,4,6,7

Why the loop? Its displaying the good numbers twice and also appends
them into the table twice.

Nov 13 '05 #1
5 1770
Here is what happens if I put in a good number and then a bad number
(the reverse of the above example)

Step 0,2,3,5
Tells me one is bad and to redo it. I then put 2 good numbers in.
Step 0,2,3,4
It shows me the 2 employees
Step 6,7
It shows me the 2 employees again!
Step 6,7

Its like the "End Function" isn't getting applied in the append module.
Almost as if it remembers where the input error was and after 2 good
numbers are in there, it has to go back to the error spot and redo it.

Nov 13 '05 #2
bump*

Nov 13 '05 #3
Bruce,
I lost track of your code after finding that get_clock calls
verify_clock and verify_clock calls get_clock, in other words
unintended recursion which might cause extra actions as it unwinds. You
might also try writing w/o gotos which can also cause unexpected
actions and make it difficult to explain code to others.

Good Luck!

Nov 13 '05 #4
First, thanks for taking some time to review my code. I admit its not
structured the best but it was my first stab at VB with access.

To sum the code up as simple as I can.... There is an SQL passthrough
query called "lookup_emp_id" that taps into an SQL server that provides
a list of employee names and their clock numbers. Its defined on the
query tab.

get_clocks asks for 2 employee numbers. It then goes to verify_clock
which takes the 2 numbers they entered from step one and looks them up
in the SQL pass through query. If it finds each record clocknum 1
time, it goes to append. Otherwise if one of those are wrong, it tells
them someone isnt clocked in and goes back to get_clocks for 2 numbers
again. It continues to do this until dcount on both = 1.

The problem is that if you put 1 of those numbers in wrong, it doesn't
find them. Infact if you enter a wrong number in 2 times it loops 2
times. You'll notice that after step7 is called, it should end the
function but it doesn't. It goes back to the code where it found a
wrong number.

Nov 13 '05 #5
Just to let you all know, we fixed the problem.

The issue was that I was calling a function B from within function A
and when the error occured in B, it was going back to the beginning of
A which in turn called B all over again and hence the "loop".

What I did was created an extra function that gathers the clock numbers
and does not call any other functions. Hard to explain but sleep well
knowing my problem is resolved :)

Thanks to everyone that took their time out to look at this.

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Randell D. | last post by:
Folks, I feel like pulling my hair out - I tried unsuccessfully over the past few days to install ImagMagick but because of version conflicts and missing libraries I had to give up. I originally...
2
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience,...
7
by: Alex | last post by:
Hi all, I've found a module that I think will help me combine fields properly, but I'm unsure how to add or use it with Access 2000. Below is the module I'd like to add: ...
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
16
by: didier.doussaud | last post by:
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : .... import math .... def f() : global math # necessary ?????? else next line...
4
by: downwitch | last post by:
Hi all, Wondering if there is a way to determine that a given module is a class module or not. In looping through the AllModules collection, it would be useful for me to do different things...
17
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
6
by: xkenneth | last post by:
Looking to do something similair. I'm working with alot of timestamps and if they're within a couple seconds I need them to be indexed and removed from a list. Is there any possible way to index...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
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: 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
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
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
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.