ascertaining minimum value

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

Ascertaining a minimum value

resolvedResolved · 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

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:

Prefixed Autonumbering

When using Date Type = Autonumber as a primary key, clients may require autonumbering to be prefixed with a letter.

For example, P001, where P is the prefixed letter

Instructions
Step 1. Create Field Name
Step 2. Set Data Type to Autonumber
Step 3. Within Field Property General tabsheet,
enter Format property as [backslash]P000



View all Access hints and tips


Server loaded in 0.07 secs.