Solved

Right Justificacion in textbox control conflicts with null values stored in recordsets.

Posted on 2003-11-10
4
210 Views
Last Modified: 2010-05-01
I'm working with VB6 and SQL 7, with ADO. I have a form with a master table that allows the null value in some of the fields. And I have many TextBox controls to show thew info. Well, when I link the fields to the controls, I need the right justification to numbers, ok ? I do that as follows:

Set txtSpread.DataSource = rsAirplanes.DataSource
txtSpread.DataMember = rsAirplanes.DataMember
txtSpread.DataField = "Spread"
txtSpread.Alignment = vbRightJustify

And if I avoid the last line thew program runs with no problems, so how to do the justificacion but keeping the null values, of course ?

thank you very much for you atenttion.
0
Comment
Question by:pilotgabriel
[X]
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
  • 2
4 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9716942
Have you tried:

If Not IsNull(txtSpread) Then txtSpread.Alignment = vbRightJustify
0
 

Author Comment

by:pilotgabriel
ID: 9717071
no, because I defines the linking of all the fields first of all, at the Form Load event, and then when the program retrieve the recordset I do this:

txtSpread.Text = IIf(IsNull(rsAirplanes.Fields("Spread").Value), "", rsAirplanes.Fields("Spread").Value)

It runs ok, but it is only to get the recordset. Then, at the moment of executing any move method becomes the error. Microsoft says that execution the instruction recordset.move 0 will solve that, by is lie, it gives the same error.
0
 
LVL 17

Accepted Solution

by:
inthedark earned 500 total points
ID: 9717216
What happens if you set the Alignment first?
txtSpread.Alignment = vbRightJustify ' do first or at design time
Set txtSpread.DataSource = rsAirplanes.DataSource
' etc....

Another good affect for numeric data entry is to do something like this....so when you enter into a field the data moves to left left side of the box, but it depends how the operator wants it.

Private Sub Text1_GotFocus()
on error resume next
Text1.Alignment = vbLeftJustify
End Sub
Private Sub Text1_LostFocus()
on error resume next
Text1.Alignment = vbRightJustify
Text1 = Format(GitNum(Text1), "0.00")
End Sub

Public Function GitNum(RSField)

' Force a null item to be numeric

If IsNull(RSField) Then
    GitNum = 0
Else
    GitNum = RSField
End If

End Function
0
 

Author Comment

by:pilotgabriel
ID: 9717562
Ok, I did the first thing you said I runs perfect !
To show as an example, this way was wrong:

Set txtSpread.DataSource = rsAirplanes.DataSource
txtSpread.DataMember = rsAirplanes.DataMember
txtSpread.DataField = "Spread"
txtSpread.Alignment = vbRightJustify

but this way the program executes with no error:

txtSpread.Alignment = vbRightJustify
Set txtSpread.DataSource = rsAirplanes.DataSource
txtSpread.DataMember = rsAirplanes.DataMember
txtSpread.DataField = "Spread"

I don't no why, but the problem is solved, thank you very much ! I'll give the points of the answer.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

724 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