Replace NULL values from database for MSFLEXGRID

Posted on 2004-09-30
Last Modified: 2008-02-26
How can I replace empty or NULL values pulled from a database and display them as "Unknown" or just an empty string? I'm using MSFLEXGRID and I need it to display something when no value is present, because I am pulling data using msflexgrid.text and editting it in a textbox. Any help would be appreciated...
Question by:Yeavis
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
LVL 18

Expert Comment

ID: 12196011
Add 2 double quotes on the end of each field value. e.g.

Dim sMyString as String
sMyString = MyRecordset.Fields(1).Value & ""

This will just give the string a value of an empty string if the recordset value is null and won't cause any error.


Author Comment

ID: 12196022
Okay I understand what you're saying.. but the column on the flexgrid could or could not contain information. Basically I have an inventory program and some information might not apply to all inventory items. When the grid is filled I need to replace any empty values.. so when the user clicks on a row to edit the information the text boxes can be filled without generating an error.
LVL 18

Expert Comment

ID: 12196120
I'm not sure I quite understand what you are trying to do. When do you get the error?
You can replace empty values in a FlexGrid with anythin you like e.g.:

Private Sub Command1_Click()
    Dim i As Long
    Dim j As Long
    With MSFlexGrid1
        For i = 0 To .Rows - 1
            For j = 0 To .Cols - 1
                .Row = i
                .Col = j
                If .Text = "" Then
                    .Text = "f " & i & " " & j
                    .Text = "Row  " & i & " Col " & j
                End If
            Next j
        Next i
    End With

End Sub
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12196547
Okay the code you gave me worked! The only strange thing is that when i click on one of them I see a bunch of ROW 1 COL 1 (or whatever the row and column are) dislayed as text until the grid itself is populated from the database. Is there anyway to hide this?
LVL 10

Expert Comment

ID: 12197130
hi Yeavis

instead of using Text property in above code.

try to use .TextMatrix(row, col) property of MSFlexGrid..

Author Comment

ID: 12197423
I tried changing the code to use textmatrix but it is giving an invalid argument error. Could you please modify the above code and show me what I did wrong? Thank you..
LVL 10

Expert Comment

ID: 12197460
  Dim Row As Long
    Dim Col As Long

    With MSFlexGrid1
   while not rs.eof
      for col= 0 to rs.fileds.Count-1
      .TextMatrix(Row,Col) = Rs(Col) 'where RS(i) is the Field data for which u want  
     Row = Row + 1

Also If uy could post ur code.. i might help u better way
    End With
LVL 18

Accepted Solution

JR2003 earned 75 total points
ID: 12198105
In the If statement in my previous message change:

   .Text = "Row  " & i & " Col " & j


  .Text = " "

Author Comment

ID: 12207097
Worked beautifully.. thank you very much for the help!

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

688 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