Solved

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

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

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

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 about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now