Solved

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

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

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…

840 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