Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

ascertaining minimum value

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Ascertaining a minimum value

Ascertaining a minimum value

ResolvedVersion 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

Edited on Wed 8 Oct 2008, 09:58

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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Dsum

You can create percentage values based on individual products / items by using a Dsum function (used with a grouped query)

[Each value column] / Dsum[field:total for the column needed to be calculated],[tablename]

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.