Solved

Replace NULL values from database for MSFLEXGRID

Posted on 2004-09-30
9
387 Views
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...
0
Comment
Question by:Yeavis
  • 4
  • 3
  • 2
9 Comments
 
LVL 18

Expert Comment

by:JR2003
Comment Utility
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.

JR
0
 

Author Comment

by:Yeavis
Comment Utility
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.
0
 
LVL 18

Expert Comment

by:JR2003
Comment Utility
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
0
 

Author Comment

by:Yeavis
Comment Utility
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?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 10

Expert Comment

by:anv
Comment Utility
hi Yeavis

instead of using Text property in above code.

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

Author Comment

by:Yeavis
Comment Utility
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..
0
 
LVL 10

Expert Comment

by:anv
Comment Utility
  Dim Row As Long
    Dim Col As Long
Row=0
Col=0

    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  
display
     next
     Row = Row + 1
      rs.movenext
   wend

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

Accepted Solution

by:
JR2003 earned 75 total points
Comment Utility
In the If statement in my previous message change:

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

To:

  .Text = " "
0
 

Author Comment

by:Yeavis
Comment Utility
Worked beautifully.. thank you very much for the help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now