Solved

Define field length for query results

Posted on 2008-06-26
5
813 Views
Last Modified: 2008-07-03
I currently have a table of information in access that I need to query certain fields with.  

The issue is that I can not define a field length for the query's results.
For example:
Lname must have a field length of 30 regardless of use
TermHrs must have a field length of 3 regardless of use

I've tried left(), mid(), right(), substr()...and none of them have worked.  
0
Comment
Question by:Jond0312
  • 3
5 Comments
 
LVL 3

Expert Comment

by:darkmooink
ID: 21875806
len()
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 21875844
try this:

Lname1: mid([Lname],1,30)
TermHrs1: mid([TermHrs],1,3)

jaffer
0
 

Author Comment

by:Jond0312
ID: 21875921
I tried

mid([Lname],1,30) & mid([Fname],1,30)

my results...

DerekKellgren

i need

Derek________________________Kellgren______________________
0
 
LVL 27

Accepted Solution

by:
jjafferr earned 500 total points
ID: 21876920
Do you mean you want the rest of the space to be BLANKS? or Underscores??

you will need a Function to do this,
save the following in a module:



now in your query, call this function, like this:
Lname1: FormatText([Lname], 30)
Public Function FormatText(txt As String, iDigits as integer)
dim NewT, i 
    For i = Len(txt) + 1 To iDigits 
        NewT = NewT & " "   'replace the space between the quotes with whatever you want to fill the rest of the spaces
    Next i
    FormatText = txt & NewT
    
End Function

Open in new window

0
 
LVL 27

Expert Comment

by:jjafferr
ID: 21876942
for [Lname]  and  [Fname]

FullName:FormatText([Lname], 30) & " " & FormatText([Fname], 30)
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question