VB4.0/16 bit/Access 2.0/DBGrid

Posted on 1997-06-15
Last Modified: 2012-08-14
I am creating a user interface to easily search an Access 2.0 database and display only a few fields from one table in a DBGrid that is bound to a data control.  One of the fields contains many lines of text.  How do I wrap the text in that column of the grid so the user can see it all at once without having to horizontally scroll within the cell?  It seems like this should be fairly easy, but I've tried everthing I can think of.  Can you please help?
Question by:STKeith
  • 4
  • 2

Expert Comment

ID: 1427285
Maybe you should use a function as a result for that special column. The function itself should do the word-wrapping an insert an LF/CR after lets say 30 chars.

Accepted Solution

tward earned 100 total points
ID: 1427286
Along with what BBC said I believe you also have to adjust the RowHeight for each line.  At least I know it is this way with the regular GRID, after putting in the CR (was all I needed) I then had to adjust the RowHeight to be equal to the height of the text*the number of lines of text.

Author Comment

ID: 1427287
Edited text of question
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 1427288
Adjusted points to 100

Author Comment

ID: 1427289
I have tried adjusting the RowHeight, but the text does not continue to the next line of the cell.  According to the online help for DBGrid, the text should automatically wrap to the next line but its not.  I'm afraid that if I use a function to retreive and modify all of the text for that column that it will slow things down too much.  Is there anyway around this?

Expert Comment

ID: 1427290
As far as I know there is not a way around this.  The on-line help for the GRID says the same thing but I to found this not to be true so I simply go into the string and put a CR in the string several times to split the string up where I needed to.  This might help, it is some word wrap code that someone gave to me, this puts a CRLF pair but it could easily be changed to put just a CR.

Public Function WordWrap(St$, Length As Integer) As String

'-- This function converts raw text into CRLF delimited lines.
    Dim Cr$, CrLF$, NextLine$, Text$
    Dim L, S, C As Integer
    Dim DoneOnce As Boolean

    Length = Length + 1
    St$ = Trim$(St$)
    Cr$ = Chr$(13)
    CrLF$ = Chr$(13) & Chr$(10)

        L = Len(NextLine$)
        S = InStr(St$, " ")
        C = InStr(St$, Cr$)

        If C Then
            If L + C <= Length Then
                Text$ = Text$ & NextLine$ & Left$(St$, C)
                NextLine$ = ""
                St$ = Mid$(St$, C + 1)
                St$ = Mid$(St$, C + 1)
                GoTo LoopHere
            End If
        End If
        If S Then
            If L + S <= Length Then
                DoneOnce = True
                NextLine$ = NextLine$ & Left$(St$, S)
                St$ = Mid$(St$, S + 1)
            ElseIf S > Length Then
                Text$ = Text$ & CrLF$ & Left$(St$, Length)
                St$ = Mid$(St$, Length + 1)
                Text$ = Text$ & NextLine$ & CrLF$
                NextLine$ = ""
            End If
            If L Then
                If L + Len(St$) > Length Then
                    Text$ = Text$ & NextLine$ & CrLF$ & St$ & CrLF$
                    Text$ = Text$ & NextLine$ & St$ & CrLF$
                End If
                Text$ = Text$ & St$ & CrLF$
            End If
            Exit Do
        End If



    WordWrap = Text$

End Function

Author Comment

ID: 1427291
Thanks tward.  This looks like it will do the trick.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 ListBox Question 4 48
Copy a range from 1..n excel sheets to one destination sheet 2 55
Problem to line 23 53
Collapse and expand table in Word 2010 2 32
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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