Address text field, focus field

Necro

New member
Local time
Today, 13:38
Joined
Sep 24, 2012
Messages
5
Hey there,

I have some, I guess quite simple questions:
-How can I address the fields on my forms? I just want to create a button that increases a value by one on click.

I tried
FORMNAME.FIELDNAME = FORMNAME.FIELDNAME + 1
FIELDNAME = FIELDNAME + 1
FORMNAME!FIELDNAME = FORNAME!FIELDNAME + 1
but the button does nothing. And that is all I found by googling.

-How to focus a field at the beginning? I want to be able to start writing always in the same field.

FIELDNAME.SetFocus

does not work.

I dont know if I made any mistake during creating tables and forms, but these codes should actually work, shouldnt they? :confused:
 
You need to work on the Button_OnClick method.. Go to design view, Click the button and on the On_Click event you have to add the code..something like..
Code:
Private Sub [COLOR=Blue]buttonNam[/COLOR]e_OnClick()
    Me.[COLOR=Blue]textFieldName[/COLOR] = Me.[COLOR=Blue]textFieldName[/COLOR] + 1
End Sub
The blue bits should match your design names.. Me. is the Short form of accessing Forms!FormName!controlName..

There is a difference between dot(.) and bang(!) operators.. How they work.. they are available on this forum as well as on the internet.. dot is normally used to refer functions of the Form/Control like textField.SetFocus, buttonName.Visible and bang is used to refer to the controls in the collection, like Forms!formName!controlName
 
create a button and cancel out of the wizard.. right-click and choose build event and code builder. Your code should look something like:

Private Sub YourButton_Click()
Me.YourField = Me.YourField + 1
End Sub

Regarding the setfocus you could look at the tab stop property on the fields, the tab order on the form and maybe the form cycle property!~)
 
thank you both for your answers! :)

I used the Button_OnClick method.

@pr2-eugin: What to you mean by controllName?

I only found this:
msdn .microsoft .com/en-us/ library/office/aa158802%28v=office.10%29.aspx

and there's no text field? But only the text box?

Because it does not work like this
Code:
Forms!FormName!TextFieldName = ...
or
Code:
Forms!FormName.TextFieldName = ...
 
I tried Me.FieldName as well.

But it is still not working.
Does it matter, that this field is connected to a table? It should increase the value of the table as well...
 
No, it should work, both in Form and Table.. What is the Name of the Field that you are trying to change? What is the button name? Show me the 'actual' code you have put in the Form..
 
Thank you very much!
It finally works :)

Access blocked some informations due to security reasons... Now I allowed it and it is working. Sorry...
 

Users who are viewing this thread

Back
Top Bottom