473,811 Members | 4,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with function.

101 New Member
Hi, my project is in MS Access 2002.
In that I have one form.In that thare are couple of textboxes and a combobox.
now at first i select perticular number from combobox(AutoNo )
then it will fetch the value of PalletNo from table and set it as the value of textbox(PalletN o)
In my table there entries like
AutoNo PalletNo
1 | 21400
2 | 21401
3 | 21402
1 | 21403
1 | 21404
2 | 21405
etc


Now if i select "1" from AutoNo then it will return value ";21400;21403;2 1404" in textbox (PalletNo).

so
AutoNo = 1
PalletNo = ;21400;21403;21 404

Now I have one more TextBox(PalletN o1)
now i want to check that value i enter in textbox(PalletN o1) is in textbox(PalletN o) or not.And if its there then change the background color of textbox(PalletN o1) to GREEN.and if not then RED.

Like
AutoNo = 1
PalletNo = ;21400;21403;21 404
PalletNo1=21403


I am using code like this

Private Sub PalletNo1_After Update()

Dim i As Integer
Dim j As Integer
Dim LongVariable As String
Dim ResultString As String
j = CountValues(PalletNo)
For i = 1 To j
LongVariable = ReturnPalletNo(i, PalletNo)
If (Me.PalletNo1 = LongVariable) Then
Me.PalletNo1.Ba ckColor = 255
Else
Me.PalletNo1.Ba ckColor = 65280
End If
Next i
End Sub
and two functions i created are like this

Public Function CountValues(Ent ryString As String) As Integer
Dim EntryCounter As Integer, EntryLength As Integer
Dim i As Integer, CharCount As Integer, ch As String
Const Separator = ";"
EntryLength = Len(EntryString )
For i = 1 To EntryLength
ch = Mid$(EntryStrin g, i, 1)
If ch = Separator Then
If CharCount > 0 Then
EntryCounter = EntryCounter + 1
CharCount = 0
End If
Else
CharCount = CharCount + 1
End If
Next i
If CharCount > 0 Then
EntryCounter = EntryCounter + 1
End If
CountValues = EntryCounter
End Function
and the other one is

Public Function ReturnPalletNo( EntryNumber As Integer, EntryString As String) As Long
'Returns the specified pallet number from the entry string, or
'0 if the EntryNumber is invalid
Dim EntryCounter As Integer, EntryLength As Integer
Dim t As Integer, i As Integer, w As Integer, m As Integer, o As Integer, CharCount As Integer, ch As String
Dim ResultString As String, ReturnValue As Long
Const Separator = ";"
If (EntryNumber <= 0) Or (EntryNumber > CountValues(Ent ryString)) Then
ReturnValue = 0
Else
EntryLength = Len(EntryString )
Do While (i < EntryLength) And (EntryCounter <> EntryNumber)
i = i + 1
ch = Mid$(EntryStrin g, i, 1)
If ch = Separator Then
If CharCount > 0 Then
EntryCounter = EntryCounter + 1
CharCount = 0
End If
Else
CharCount = CharCount + 1
If CharCount = 1 Then
ResultString = ch
If (Me.PalletNo1 = ResultString) Then
Exit Do
End If
Else
ResultString = ResultString & ch
If (Me.PalletNo1 = ResultString) Then
Exit Do
End If

End If
End If
Loop
End If
If ResultString <> "" Then
ReturnValue = Val(ResultStrin g)
End If
ReturnPalletNo = ReturnValue
End Function
when i run the form it will simply execute the code but it won't match the values
ReturnPalletNo = ReturnValue
it always return the last PalletNo in my Entrystring.
I can't get it what's problem with code.
Can anyone help me.
Thank You.
Mar 14 '08 #1
4 1295
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Billa. As the person who wrote the CountValues and ReturnPalletNo functions for you in response to a previous post I note that you have changed the ReturnPalletNo code significantly and included additional IFs etc which are specific to your forms. These functions were tested and did function correctly when supplied to you - see thread http://www.thescripts.com/forum/thread775535.html.

When I remove your additional code the ReturnPalletNo function works again as when I supplied it to you, and I would suggest that you use the original code and this alone in your application. Its sole purpose was to provide you with the ability to extract pallet numbers from your string lists, and it works in exactly the way it is supposed to do.

-Stewart
Mar 14 '08 #2
billa856
101 New Member
I made very silly mistake but now I got the problem.
i was using
Exit For
, in funtion(ReturnP alletNo) itself.But i have to use it after function return the value.So i replace the code of functions to origanl code given by u before ,and Now finaly its working in very properly manner I want.


Dim i As Integer
Dim j As Integer
Dim LongVariable As String
Dim ResultString As String
j = CountValues(Pal letNo)
For i = 1 To j
LongVariable = ReturnPalletNo( i, PalletNo)
If (Me.PalletNo1 = LongVariable) Then
Me.PalletNo1.Ba ckColor = 255
Exit For
Else
Me.PalletNo1.Ba ckColor = 65280
End If
Next i
End Sub
Thanks a lot for ur help.
Mar 14 '08 #3
billa856
101 New Member
Now I am using this function again in another form.

In that I have one ListBox(PalletI DOrTrackingNo_L istBox) and one textbox(LONO_Te xt).
Now when I select an item from ListBox then it will check using these function that it is already in that TextBox or not?if not then it will enter the value in Textbox and if it is already in that then leave it as it is.

for that I am using this code

Private Sub PalletIDOrTrack ingNo_ListBox_A fterUpdate()
Dim var As Variant
Dim j As Integer
Dim y As Integer
Dim LongVariable As String

For Each var In Me.PalletIDOrTr ackingNo_ListBo x.ItemsSelected

If (IsNull(Len(Me. LONO_Text))) Then
'if Textbox is empty then it simply enter item in it.
Me.LONO_Text = Me.LONO_Text & ";" & Me.PalletIDOrTr ackingNo_ListBo x.ItemData(var)

Else

j = CountValues(Me. LONO_Text)
'PROBLEM IS IN THIS LOOP
For y = 1 To j
LongVariable = ReturnPalletNo( y, Me.LONO_Text)

If (Me.PalletIDOrT rackingNo_ListB ox.ItemData(var ) = LongVariable) Then

Exit For

Else

Me.LONO_Text = Me.LONO_Text & ";" & Me.PalletIDOrTr ackingNo_ListBo x.ItemData(var)

End If
Next y
End If

Next var
End Sub
In that Loop first time(y=1; j=1) when item is not in list,it will simply enter it in but next time(y=1;j=2),i t will check again from first item and it not match the criteria so again it will enter item and next time(y=2;j=2)it will check again and it will enter item.

I think below is the solution for this problem but i don't know how to use it.
In this loop first it has to compare the value of item I selected from listbox to all values in textbox.then if it is already in textbox then leave it as it is and not then it will enter item in textbox.

I try to explain by example.
For Example
List is like this in Listbox(Me.Pall etIDOrTrackingN o_ListBox)

LONO|PalletNo|D escription-----------|BatchNO|CRTN|P cs|Total|remain |Location
->1------|2---------|3---------------------------------|4---------------|5----|6----|7-----|8------|9--------


->7807 | 21102 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7807 | 21103 | DKNY BE DELICIOUS | 79658BV3 | 30 | 10 | 300 | 300 | 256BB
->7807 | 21104 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7808 | 21105 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
->7808 | 21106 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
->7807 | 21107 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7807 | 21108 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7808 | 21109 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD

Now if I select first one 7807 then LONO_Text=;7807
After that if again I select 7807 then LONO_Text will remain as it is.
then if I select 7808 then LONO_Text=7807; 7808
then if i select 7807 then LONO_Text=7807; 7808

then if i select 7808 then LONO_Text=7807; 7808;7808;7808
but it should be LONO_Text=7807; 7808

I hope I explained properly what I want by example.
Help me plz.
Mar 25 '08 #4
billa856
101 New Member
I solve the previous problem.
But now there is another one coming

List is like this in Listbox(Me.Pall etIDOrTrackingN o_ListBox)

LONO----|PalletNo|Descr iption-----------|BatchNO--|CRTN|Pcs|Total |Remain|Locatio n
->1------|2---------|3----------------------------|4-------------|5----|6----|7-----|8-----|9--------

->7807 | 21102 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7807 | 21103 | DKNY BE DELICIOUS | 79658BV3 | 30 | 10 | 300 | 300 | 256BB
->7807 | 21104 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7808 | 21105 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
->7808 | 21106 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
->7807 | 21107 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7807 | 21108 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
->7808 | 21109 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD

How can I add selected items from column 8(Remain)?
Like If I select first line then TotalRemain=200
then If I select 2nd line then TotalRemain=200 +300=500
then If I select 3rd line then TotalRemain=200 +300+200=700

then If I disselect 2nd line then TotalRemain=200 +300+200-300=400


I am using this code but its not working properly

For Each var In Me.PalletIDOrTr ackingNo_Combo. ItemsSelected
Me.TotalQuantit y1 = Me.TotalQuantit y1 + Me.PalletIDOrTr ackingNo_Combo. Column(8, var)
Next var
using this code things gone like this

Like If I selected first line then TotalRemain=200
then If I select 2nd line then TotalRemain=200 +200+300=700 instead of 200+300=500
then If I select 3rd line then TotalRemain=200 +200+300+300+20 0=1200 instead of 200+300+200=700

then If I disselect 2nd line then TotalRemain=200 +200+300+300+20 0+1200=2400 instead of 200+300+200-300=400


I don't get it why this is happening but i Think its bcz I am using FOR EACH.
can anyone help me?
Mar 27 '08 #5

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

Similar topics

1
20705
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
7
2442
by: Emanuel Ziegler | last post by:
Hello, I want to do some mathematics with functions. In my case the function classes are very complex, but this simple example has the same problems. To allow calculations that begin with a double, I have to define a global operator+ (or -*/) and special function classes. --- source begins here ---
117
7278
by: Peter Olcott | last post by:
www.halting-problem.com
1
3649
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL (CALLBACK* ExProcessMessage)(UINT msg, LPVOID lpParam); // ExProcessMessage MyProcMsg;
4
6035
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This should be easy enough to do using the MID function in a For...Next statement. However, I've had more than a few problems. My first problem was that I had a data type mismatch. Access simply refused to evaluate anything I put in there no matter...
0
1601
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
78
4987
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my little helper function doesn't work! It claims that a variable doesn't exist. If I move the variable declaration, it finds the variable, but can't change it. Declaring the variable global in the nested function doesn't work...
5
14819
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause huge problems with slow connect times and heavy resource locking in high concurrency / high transaction volume environments. I have an OLTP with 30-90 transactions per second activity, and start of Health Monitor every 2 hours was crashing our...
2
7414
by: Ravikiranreddy | last post by:
Hi every one, Am pasting the error code returned in log please help me in fixing it--- ERROR:An error occurred during the execution of the command "/opt/IBM/db2/V8.1/instance/dascrt -u dasusr1 -d". The DB2 Administration Server may not function properly. The return value is "1". ERROR:## call function cleanup_reg_list das crt dasusr1 ## call function create_das
6
4555
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10138
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9214
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4353
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 we have to send another system
2
3879
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.