Make textbox keep the last value

  • Thread starter Combo box type - help
  • Start date
C

Combo box type - help

Hi, i'm having a bit of a problem and i'm not getting where i want.. I have a
textbox on one form that i need to keep the last value(before closing the
form the last time it was used).. There's an input box connected to it, where
i can change the value (that's working ok) but i want that value to remain
there after closing and opening the form..

I tried to use this code:
Me!comboName.DefaultValue = """" & Me!ComboName & """"
-It's not working.. the textbox gets blank after i close and reopen the form

I also tried this:
Dim value As double..
...on click()
value = box.value
box.DefaultValue = value
I dont know why but the code is also not working..no default value is added
to the textbox data

now i'm trying to do this, but i need your help with the code please:
Create a table only for the value i want to keep.. When i close the form (on
form_close()) i want the value on the textbox to be sent to the
table...then..when i open the form (on form_open()) i want the program to get
that value on the table..the last value added, and send it to textbox.. I
think this is the only way i can do it.. i really need that value to be saved
every time i close the form and obviously to be there when i open.. I hope
you can help me with the code..and if you know another way to do it.. be my
guest.. :)
Many thanks
Nuno
 
K

Ken Sheridan

First create a table with a single column of double precision number data
type. Lets say the table is called MyTable and the column is called
MyNumber. Enter a row into the table with any number that comes to mind.

In the form's Open event procedure put:

Me.MyTextBox = DLookup("MyNumber", "MyTable")

In the Form's Close event procedure put:

Dim dbs As DAO.Database
Dim strSQL As String

Set dbs = CurrentDb

strSQL = "UPDATE MyTable " & _
"SET MyNumber = " & Me.MyTextBox

dbs.Execute strSQL

BTW the reason that setting the control's DefaultValue property is not
working is because the form's definition is not being saved after setting the
property. You could do this by calling the save method of the DoCmd object,
but storing the value in a table is better.

Ken Sheridan
Stafford, England
 
C

Combo box type - help

Thanks Ken.. thats working ok but one problem.. its not accepting decimal
values, and the value in question is always decimal.. i tried to change only
the variable type, from string to double and give's me an error so i guess
some more change is needed.. can you help me?
Many thanks
Nuno
 
K

Ken Sheridan

The most likely cause is that the data type of the field to which the text
box is bound is an integer number. By default number fields are of ling
integer type. Change this to Double in the 'Field Size' row of the column's
property sheet in table design view.

I'm just about to leave for the airport and shall be incommunicado for the
next week, so I hope that does the trick.

Ken Sheridan
Stafford, England
 
F

Fred

that's not the problem..because i havent changed the data type in the
table.. is still Text so it should accept ",".. And i changed to double but
still giving the error.. "type mismatch" on this code:
strSQL = "UPDATE Tari " & _
"SET Tarifa = " & Me.Text47

i cant understand whats wrong..
HELP..
thanks..

"Ken Sheridan" escreveu:
 
K

Ken Sheridan

If the column's data type is text then the value must be wrapped in quotes
characters:

strSQL = "UPDATE Tari " & _
"SET Tarifa = """ & Me.Text47 & """"

and the variable should first be declared as a string:

Dim strSQL As String

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top