PDA

Click to See Complete Forum and Search --> : Integers in a textbox


cid
Jan 24th, 2006, 12:46 PM
So basically in this database there are random numbers that are some times 4 characters long and sometimes 5 characters. I tried to make a replace function like this:


Private Sub Form_Load()
On Error GoTo move_first
Do
If GIS.Value = "xxxx" Then
GIS.Value = "R00000" & GIS.Value
ElseIf GIS.Value = "xxxxx" Then
GIS.Value = "R0000" & GIS.Value
Me.Recordset.MoveNext
End If
Loop
Exit Sub
move_first:
Me.Recordset.MoveFirst
End Sub


Anyways, this just hangs the program and forces me to do a ctrl + alt + break

if anyone has any ideas, they are greatly appreciated :)

space_monkey
Jan 24th, 2006, 12:51 PM
Would this work for you?

GIS.Value = Format(GIS.Value, "R000000000")

Hack
Jan 24th, 2006, 12:52 PM
What kind of control is GIS? :confused:

cid
Jan 24th, 2006, 01:35 PM
textbox
And I dont know about that format command, because if the value in gis ='s 4 digits then there has to be "R + 5 zeros" is the gis ='s 5 digits then it has to be "R + 4 zeros"

Hack
Jan 24th, 2006, 01:38 PM
textboxIf GIS is a textbox, then your first problem is that textbox's don't have a Value property. They have Text property. GIS.Value itself should be throwing an error.

cid
Jan 24th, 2006, 01:38 PM
this is VBA(Sorry i should have clarified that)

And I believe in vba a textbox has the value property. Correct me if im wrong though.

Hack
Jan 24th, 2006, 01:41 PM
this is VBA(Sorry i should have clarified that)

And I believe in vba a textbox has the value property. Correct me if im wrong though.I believe you are correct. Having said that, however, if your post remained in ClassicVB, you would be getting other possible comments or solutions to your problem, with VB6 code, that wouldn't work (like mine) because you are using VBA.

Therefore, I've moved this to Office Development.

cid
Jan 24th, 2006, 01:43 PM
ok, thanks... any other information on my problem would be helpful.
Thanks guys.

dglienna
Jan 24th, 2006, 01:45 PM
Try a formula like this:

Option Explicit

Private Sub Form_Load()
Dim a As String, s As String
a = "124"
s = "R" & String$(10 - Len(a), "0") & a
MsgBox s & " " & Len(s)
End Sub


You might want to adjust the number 10 to suite your needs. This uses 11 digits each time.

EDIT: Just noticed the move. Hope VBA has the String$ command. I believe that it does, though.

cid
Jan 24th, 2006, 01:47 PM
im a little new but from looking at that code i gather...

A is a set variable that is equal to 124, and s is a string that inserts R and 11 zeros infront of the variable a?

I need to be able to insert "R0000" infront of a 5 digit number(random) and insert "R00000" infront of a 4 digit number. So I am not sure if your code will work with my needs.

DKenny
Jan 24th, 2006, 02:00 PM
you could add a function that will convert your input value to a string of 11 characters. Then in the _change event of the textbox call that function.

Function Code
Function Cid(Value As String) As String

Const Prefix As String = "R0000000000"

Cid = Left(Prefix, 11 - Len(Value)) & Value

End Function

_Change event code
Private Sub TextBox1_Change()
TextBox1.Value = Cid(TextBox1.Value)
End Sub

EricDV
Jan 24th, 2006, 02:04 PM
GIS.Value=Format$(GIS.Value,"R000000000")