First, Second, Third Question

LadyDi

Registered User.
Local time
Today, 11:09
Joined
Mar 29, 2007
Messages
894
Hello,

I have a quick question for you. On one of my forms, I would like to have a field that will show either, 1st, 2nd, or 3rd depending on how many times a button is clicked. I have tried adding a text box that equals "1st" and then putting an If statement on the button's On Click statement ("If Me.text33 = "1st" then Me.text33 = "2nd" End If). However, this does not seem to work. I get a debug error everytime I click the button. What do I need to do to get this to work?

Thank you for your help.
 
Hello,

I have a quick question for you. On one of my forms, I would like to have a field that will show either, 1st, 2nd, or 3rd depending on how many times a button is clicked. I have tried adding a text box that equals "1st" and then putting an If statement on the button's On Click statement ("If Me.text33 = "1st" then Me.text33 = "2nd" End If). However, this does not seem to work. I get a debug error everytime I click the button. What do I need to do to get this to work?

Thank you for your help.
Could you show me the code behind your button? I created your exact situation (I think) and it works for me. As a test I used:
Code:
    If Me.text33 = "1st" Then
        Me.text33 = "2nd"
    End If
like you said in your post.. works for me.
 
First, Second, Third

This is the code that I have behind the button.

If Me.Text33 = "1st" Then
Me.Text33 = "2nd"
End If
If Me.Text33 = "2nd" Then
Me.Text33 = "3rd"
End If

Could I be having a problem because I have the Control Source for Text33 set to "1st"? I want the text box to start out showing "1st" and that was the only way I knew to accomplish that.
 
I do not know if it is a type-o error or not, but I noticed that you have an extra " character in your formula and Erik does not.


Hello,

I have a quick question for you. On one of my forms, I would like to have a field that will show either, 1st, 2nd, or 3rd depending on how many times a button is clicked. I have tried adding a text box that equals "1st" and then putting an If statement on the button's On Click statement ("If Me.text33 = "1st" then Me.text33 = "2nd" End If). However, this does not seem to work. I get a debug error everytime I click the button. What do I need to do to get this to work?

Thank you for your help.

Could you show me the code behind your button? I created your exact situation (I think) and it works for me. As a test I used:
Code:
    [SIZE=4][COLOR=royalblue][B]If Me.text33 = "1st" Then[/B][/COLOR][/SIZE]
[SIZE=4][COLOR=royalblue][B]     Me.text33 = "2nd"[/B][/COLOR][/SIZE]
[SIZE=4][COLOR=royalblue][B] End If[/B][/COLOR][/SIZE]
like you said in your post.. works for me.
 
Could I be having a problem because I have the Control Source for Text33 set to "1st"? I want the text box to start out showing "1st" and that was the only way I knew to accomplish that.
Aha! That is indeed the problem. Control Source should not be used this way, try setting the "Default Value" property :)
 
This is the code that I have behind the button.

If Me.Text33 = "1st" Then
Me.Text33 = "2nd"
End If
If Me.Text33 = "2nd" Then
Me.Text33 = "3rd"
End If

Could I be having a problem because I have the Control Source for Text33 set to "1st"? I want the text box to start out showing "1st" and that was the only way I knew to accomplish that.

I think that this code might skip 2nd entirely, since it tests for each separately (1st gets changed to 2nd before the test for 2nd is made).

Try something like this:

If Me.Text33 = "1st" Then
....Me.Text33 = "2nd"
Else
....If Me.Text33 = "2nd" Then
........Me.Text33 = "3rd"
....End If
End If
 
First, Second, Third

The code did skip second entirely. I got that corrected and everything seems to be working as desired, but I have run into another problem. When I set the default value of the text box to "1st", it changes every entry to "1st" each time I open the form. I need the field to show the last number it had in it. In other words, after I push the button and the field changes to show "2nd", I want that entry to show "2nd" the next time I open the database. How can I make it stay the most recent number specific to the entry, but still show "1st" on a new entry?
 
In that case you're gonna have to save the value in a table. Create a table with the field, link the table to the form and use the field in the table as Control Source for your textbox. The default value can be set in the properties of the field in the table. Hope you understood what I just said, I'm too lazy at the moment to write all the steps in detail :p
 
First, Second, Third

I understand. Thank you for your help.
 
The code did skip second entirely. I got that corrected and everything seems to be working as desired, but I have run into another problem. When I set the default value of the text box to "1st", it changes every entry to "1st" each time I open the form. I need the field to show the last number it had in it. In other words, after I push the button and the field changes to show "2nd", I want that entry to show "2nd" the next time I open the database. How can I make it stay the most recent number specific to the entry, but still show "1st" on a new entry?

The Default Value Property only affects new records, not existing records. What's happening, I suspect, is that you removed the expression in Control Source, and so your textbox is now unbound. All instances of an Unbound control on all records hold the last value that was entered into any instance of the control. You need a field in your underlying table bound to your textbox.
 

Users who are viewing this thread

Back
Top Bottom