ascertaining minimum value
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

replyReply Tue 7 Oct 2008, 19:03Delegate Gillian said...

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

For upcoming training course dates see: Pricing & availability

replyReply Wed 8 Oct 2008, 09:57 Edited on Wed 8 Oct 2008, 09:58Trainer Stephen said...

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

 

Please browse our web site to find out more about
microsoft database training and other Microsoft training courses.

Access tip:

Hide Access Tables

One method of stopping your Access tables appearing in Database window, is to rename the table(s) with the prefix usys.

This converts the table into a system object, which cannot be viewed in the Database window.

You can show system objects in the Database window by the following:

Step 1: On the Tools menu, click Options.
Step 2: Click the View tab.
Under Show, select the System Objects check box.
Click OK.

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard