Solved

Define field length for query results

Posted on 2008-06-26
5
806 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Outlook Free & Paid Tools
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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