Solved

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

Posted on 2003-11-10
4
204 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

912 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

18 Experts available now in Live!

Get 1:1 Help Now