02. november 2006 - 22:18Der er
9 kommentarer og 1 løsning
Ved klik på knap, opretholde tidligere fokus
Hej alle eksperter
Jeg vil gerne lave et nummerisk tastatur i min form, hvor den automatisk flytter fokus tilbage ved klik hvor den kom fra. Altså når jeg klikker på knap "1" går den tilbage fra tidligere fokus og indsætter "1". Jeg kender godt hvordan den indsætter "1" men kan ikke få den til at gå tilbage til tidligere fokus.
Tak for hurtig respons. Men jeg ved at der er en komando, som uanset hvor du kommer fra, kan sætte focus tilbage uden at vælge me.feltnavn.setfocus osv.
Public Sub fokus() Dim ctlCurrentControl As Control Dim strControlName As String Set ctlCurrentControl = Screen.ActiveControl strControlName = ctlCurrentControl.Name Select Case strControlName Case Is = "felt1" MsgBox "du forlader felt1" Case Is = "felt2" MsgBox "du forlader felt2" Case Is = "felt3" MsgBox "du forlader felt3" End Select End Sub
og kald hændelsen med denne:
Private Sub felt3_Exit(Cancel As Integer) fokus End Sub
PreviousControl Property See AlsoApplies ToExampleSpecificsYou can use the PreviousControl property with the Screen object to return a reference to the control that last received the focus. Read-only.
expression.PreviousControl expression Required. An expression that returns one of the objects in the Applies To list.
Remarks The PreviousControl property contains a reference to the control that last had the focus. Once you establish a reference to the control, you can access all the properties and methods of the control.
This property is available only by using a macro or Visual Basic.
You can't use the PreviousControl property until more than one control on any form has received the focus after a form is opened. Microsoft Access generates an error if you attempt to use this property when only one control on a form has received the focus.
Example The following example displays a message if the control that last received the focus wasn't the txtFinalEntry text box.
Public Function ProcessData() As Integer
' No previous control error. Const conNoPreviousControl = 2483 Dim ctlPrevious As Control
On Error GoTo Process_Err
Set ctlPrevious = Screen.PreviousControl If ctlPrevious.Name = "txtFinalEntry" Then ' ' Process Data Here. ' ProcessData = True Else ' Set focus to txtFinalEntry and display message. Me!txtFinalEntry.SetFocus MsgBox "Please enter a value here." ProcessData = False End If
Process_Exit: Set ctlPrevious = Nothing Exit Function
Process_Err: If Err = conNoPreviousControl Then Me!txtFinalEntry.SetFocus MsgBox "Please enter a value to process.", vbInformation ProcessData = False End If Resume Process_Exit
Hvis vi forudsætter, at du vil tilføje tallet i enden af feltet:
Private Sub Key1_Click() NumKeyPad (1) End Sub
Private Sub Key2_Click() NumKeyPad (2) End Sub
Private Sub Key3_Click() NumKeyPad (3) End Sub
Private Sub NumKeyPad(n As Integer) Dim C As String C = Screen.PreviousControl.Name Me.Controls(C) = Me.Controls(C) & n Me.Controls(C).SetFocus Me.Controls(C).SelStart = Len(Me.Controls(C)) Me.Controls(C).SelLength = 0 End Sub
Øøøøøh. Fik du testet vores svar? Hvad blev resultatet?
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.