0

I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).

I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"

I tried this but it is not the same as pressing the same key on a keypad.

Private Sub Buton3_Click()

 Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub

I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.

Public Sub projectID_KeyPress(KeyAscii As Integer)
    MsgBox Chr(KeyAscii)

End Sub
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Juanfran
  • 41
  • 1
  • 3

1 Answers1

0

This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:

http://access.mvps.org/access/forms/frm0031.htm

I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:

Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub

Don't forget similar click events for buttons 1-9

some things that may be helpful: ! is the bang operator see: Bang Notation and Dot Notation in VBA and MS-Access

by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.

Then .Form gets the form wrapped by the subform control.

I hope this answers your question

mazoula
  • 1,221
  • 2
  • 11
  • 20