98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Access VBA Training and help » Ascertaining a minimum value
Ascertaining a minimum value
Resolved · Urgent Priority · Version 2003
Gillian has attended:
Access VBA course
Excel Advanced course
Ascertaining a minimum value
Hello,
Is there a way to take two values, and identify which is the minimum?
I have two text fields, and for each row, I want the length value of the field that has the smallest length string.
E.g. for 'lion' and 'giraffe', I would like the value of 4 to be returned, the length of the smallest word.
Thankyou
RE: Ascertaining a minimum value
Hi Gillian
Thank you for your question
The following code will solve your problem. It prompts the user for two words and uses the len function to determine the length of the words. It then returns the shortest word, or indicates that they are of the same length.
you can adapt this by setting the variables equal to your field values
Sub StringLengthComp()
Dim strFirst As String
Dim strSecond As String
strFirst = InputBox("Enter First Word")
strSecond = InputBox("Enter second Word")
If Len(strFirst) = Len(strSecond) Then
MsgBox "Both words are the same length"
Exit Sub
End If
If Len(strFirst) > Len(strSecond) Then
MsgBox strSecond
Else
MsgBox strSecond
End If
Regards
Stephen
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Access tip:Prefixed AutonumberingWhen using Date Type = Autonumber as a primary key, clients may require autonumbering to be prefixed with a letter. |