Code not working

endri81

Registered User.
Local time
Today, 15:11
Joined
Jul 5, 2010
Messages
121
Hi I have 2 textboxes.By entering different number values to the first I want to return text to the other.For now my code is like that but not working :
Private Sub Text430_AfterUpdate()

If (Me!Text430.Value = 1) Then
Me!Text431.Value = "BR"
ElseIf (Text430.Value = 2) Then
Me!Text431.Value = "BZ"
ElseIf (Text430.Value = 3) Then
Me!Text431.Value = "DL"
ElseIf (Text430.Value = 4) Then
Me!Text431.Value = "DV"

End If
End Sub

Please help
Regards
 
That code should be fine, assuming the first textbox is formatted as number.

If it's left as text then the numbers in the VBA need to be treated like a string, i.e. surrounded by "s.
 
I put textbox format general number and use event AfterUpdate.
The cursor just go after entering 1 and pressing Enter to the other textbox431 but doesnt show anything.
What I am doing wrong?
Regards
 
Have you tried:

Code:
If (Me!Text430.Value = [B]"[/B]1[B]"[/B]) Then

I don't think the "s should be required but it's worth checking.
 
The same:(((((
Both text boxes are unbound.Can this affect to the process?
Regards
 
Shouldn't make a difference.

Are the two textboxes in the same form (or specifically not with one on a subform / both on different subforms)?
 
yes they are in the same form.Don't understand what's happening
 
Try this to confirm what the value of the textbox is.

Code:
Private Sub Text430_AfterUpdate()
 
msgbox Me!Text430.Value
 
End Sub
 
Code:
Private Sub Text430_AfterUpdate()
If Me.Text430 = 1 Then
Me.Text431 = "BR"
ElseIf Me.Text430 = 2 Then
Me.Text431 = "BZ"
ElseIf Text430 = 3 Then
Me.Text431 = "DL"
ElseIf Me.Text430 = 4 Then
Me.Text431 = "DV"
End If
End Sub

In almost every case (especially programming) less is most certainly more.
 
Not working.Any email where to send my db cause dont want to publish all work here
 
Still nothing.
Have u guys any email where I can send my db cause dont want to publish all it here.
 
Not working.Any email where to send my db cause dont want to publish all work here

If that does not work, I would suggest that you create a new form and try it. because it worked fine on a brand new form for me.

If it does not work I would bet that something is wrong with that form. Actually try it in a brand new database.
 
If you have a list of numbers and a corresponding list of values, why not change the two textboxes into a multi-column combobox?

No need for VBA at all that way. Although if you do want to refer to the values of each column in VBA you can specify so you can call both values from a single control.
 
If you have a list of numbers and a corresponding list of values, why not change the two textboxes into a multi-column combobox?

No need for VBA at all that way. Although if you do want to refer to the values of each column in VBA you can specify so you can call both values from a single control.

My next sugestion was going to be, never store data in code.
Second if I were going to make a combo box I would only do them bound to a table.

Then you could have an admin function on a form somewhere to add to the list.
 
My next sugestion was going to be, never store data in code.
I didn't suggest doing so, I just said that he could easily access the value of any column in a multi-column database if he wanted to.

And I use recordsets to store data in VBA all the time, especially audit trails in AfterUpdate events, etc. I have yet to have a single issue with this.
Second if I were going to make a combo box I would only do them bound to a table.

Then you could have an admin function on a form somewhere to add to the list.

It depends on the situation, but going by the OP I would agree in this case. There are numerous cases where the list will not change ("complete" / "Incomplete", Active" / "Inactive", etc) however for the most part I prefer to have a table feeding the combobox and having some kind of admin form to allow certain uisers to maintain the table themselves.


Btw, when I first read your post I saw "bound to a table" as in the control being bound to a table. I assume what you means was the row source being a table as there is no reason that a combobox control needs to be bound to a field on a table.
 
CBrighton
I know you were not advocating storing data in code, I think endri81 was, 1= BR, and 2 = BZ, sounds like data stored in the code.

I was on a one track mind to tell him not to store data as code when you beat me to it.

Of course you are correct; the row source should be a table.

endri81
Back to the combo box, I would say that for every 500 times this comes up, a combo box is the way to go for 499 of them.
 

Users who are viewing this thread

Back
Top Bottom