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

Help comparing strings

I am trying to use the following code to reset a custom counter:
(I forgot where I got the code but it's not my own and I did not remove
and credits, this is how it came)

Function Next_Custom_Counter()
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'For this code to work, it is required that you reference the:
' Microsoft ActiveX Data Objects 2.x Library
'To reference this library, go to the Tools menu, click
'References, and select the library from the list of available
'references (version 2.1 or higher).
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
On Error GoTo Next_Custom_Counter_Err

Dim rs As ADODB.Recordset
Dim NextCounter As Long
Dim PrefixA As String
Dim PrefixB As String
Set rs = New ADODB.Recordset

'Open the ADO recordset.
rs.Open "CounterTable", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

'Get the next counter.
NextCounter = rs!nextavailablecounter
PrefixA = rs!CurrentPrefix 'stored in table as format(Date,"yymmm")
PrefixB = Format(Date, "yymmm")

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'Open table and get the current value of NextAvailableNumber,
'increment the value by 10, and save the value back into the table
'
'The next line can be changed to conform to your custom counter
'preferences. This example increments the value by 10 each time.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''

If StrComp(PrefixA, PrefixB, vbTextCompare) = 0 Then
MsgBox ("same")
GoTo Increase
Else
GoTo Reset
MsgBox ("different")
End If
Increase:

rs!nextavailablecounter = NextCounter + 1
NextCounter = rs!nextavailablecounter
rs.Update

rs.Close

Set rs = Nothing

Next_Custom_Counter = NextCounter

Exit Function
Reset:
rs!nextavailablecounter = "0000"
rs.Update
rs.Close

Set rs = Nothing
Exit Function

[/code]

Nothing happens during the if statement. It will not even pass along
the custom counter to the call from the form. What I understood from
the A2K helpfile is that if the strings were equal it would return a 0.
What I want it to do is if the prefixb (IE: 05APR) is the same as the
current prefix (IE:05APR) then nothing happens and the counter
continues on. If there is a difference (IE: different year or month)
the counter is reset to 0.

Any help would be greatly apprecetaed as midnight trips to work to
reset the number manualy is getting old.

Dave
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''
'The following error routine should be replaced with a custom
'error routine. This example only resumes execution when an error
'occurs. If a record locking error occurs this is fine; however,
'any non-record locking error will result in an infinite loop.
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''
Next_Custom_Counter_Err:
MsgBox "Error " & Err & ": " & Error$
If Err <> 0 Then Resume
End
End Function

Nov 13 '05 #1
1 1668
Surely something is happening in the If statement, if in fact code
execution makes it that far since the If...part handles one condition
and the Else handles any other possible condition!

Try setting a breakpoint on the 'If StrComp...' line and run the code.
Examine the contents of PrefixA and PrefixB to see if they're really
what you think they should be. Then step through a line at a time and
see what's going on.

Bruce

Nov 13 '05 #2

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

Similar topics

5
by: beliavsky | last post by:
By mistake I coded something like print ("1" > 1) and got the result "True". Comparing an integer and a string seems meaningless to me, and I would prefer to have an exception thrown. Can...
26
by: William Park | last post by:
How do you compare 2 strings, and determine how much they are "close" to each other? Eg. aqwerty qwertyb are similar to each other, except for first/last char. But, how do I quantify that? ...
5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
5
by: Curtis Gilchrist | last post by:
I am required to read in records from a file and store them in descending order by an customer number, which is a c-style string of length 5. I am storing these records in a linked list. My...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
6
by: BrianJones | last post by:
I have a problem with the int strcmp(str1,str2) function: When I do: char *pass; char *passv; pass = getpass("Please enter....."); passv = getpass("Please verify.....");
3
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it...
88
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
2
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.