07. maj 2007 - 09:45Der er
10 kommentarer og 1 løsning
Undgår at indhold i felt markeres ved åbning af formular
Jeg har en formular, der anvendes til bemærkninger ved gennemgang af revisionssager. Der er kun et felt i formularen, og derfor er feltet aktivt ved åbning af formularen. Men hvordan undgår jeg, at indholdet i feltet er markeret ved åbning? - et forkert tastetryk, og hele indholdet i feltet er slettet. Jeg kan slå den fra i Funktioner - Indstillinger, men så virker det jo alle steder i databasen, hvilket ikke er hensigtsmæssigt.
Hvis det ikke er meningen at rette i feltet, kan du bruge egenskaben Aktiveret og sætte den til Ja. Hvis du så vil rette i feltet, kan du bruge denne i en kommandoknap:
Jeg bruger feltet til løbende indtastning, efterhånden som en sag skrider frem. Jeg har måske forklaret mig forkert - problemet er, at når jeg åbner formularen, er indholdet i feltet allerede markeret (den er sort) - dvs. at hvis jeg af vanvare begynder at skrive, inden feltet er helt åbent (vi har travlt ved det offentlige)forsvinder al den tidligere indtastede tekst, og den kan jo ikke genskabes.
Hej mugs og on !! Den sidste løsning fra on fungerer perfekt, og det er dejligt, at den starter ved slut af den sidst skrevne tekst. Desværre synes jeg ikke, at den vil sætte et mellemrum ind ved at anvende din løsning mugs. Men det var et godt forsøg. Lige et allersidste spørgsmål - jeg har aldrig før set functionerne SelStart og SelLength - og en søgning i den danske Access giver ikke nogen hits - hvorledes virker de (for de virker aldeles glimrende her). Og så må points gå til on, på trods af dit behjertede forsøg mugs. Mange tak for hjælpen til jer begge. bbkdk
The SelStart property specifies or determines the starting point of the selected text or the position of the insertion point if no text is selected. Read/write Integer.
expression.SelStart
expression Required. An expression that returns one of the objects in the Applies To list.
Remarks The SelStart property uses an Integer in the range 0 to the total number of characters in a text box or text box portion of a combo box. You can set the SelStart property by using a macro or Visual Basic.
To set or return this property for a control, the control must have the focus. To move the focus to a control, use the SetFocus method.
Changing the SelStart property cancels the selection, places an insertion point in the text, and sets the SelLength property to 0.
Example The following example uses two event procedures to search for text specified by a user. The text to search is set in the form's Load event procedure. The Click event procedure for the Find button (which the user clicks to start the search) prompts the user for the text to search for and selects the text in the text box if the search is successful.
Private Sub Form_Load()
Dim ctlTextToSearch As Control Set ctlTextToSearch = Forms!Form1!Textbox1
' SetFocus to text box. ctlTextToSearch.SetFocus ctlTextToSearch.Text = "This company places large orders twice " & _ "a year for garlic, oregano, chilies and cumin." Set ctlTextToSearch = Nothing
End Sub
Public Sub Find_Click()
Dim strSearch As String Dim intWhere As Integer Dim ctlTextToSearch As Control
' Get search string from user. With Me!Textbox1 strSearch = InputBox("Enter text to find:")
' Find string in text. intWhere = InStr(.Value, strSearch) If intWhere Then ' If found. .SetFocus .SelStart = intWhere - 1 .SelLength = Len(strSearch) Else ' Notify user. MsgBox "String not found." End If End With
SelLength Property See Also Applies To Example Specifics The SelLength property specifies or determines the number of characters selected in a text box or the text box portion of a combo box. The SelLength property uses an Integer in the range 0 to the total number of characters in a text box or text box portion of a combo box. Remarks You can set the SelLength property by using a macro or Visual Basic.
To set or return this property for a control, the control must have the focus. To move the focus to a control, use the SetFocus method.
Setting the SelLength property to a number less than 0 produces a run-time error.
Example The following example uses two event procedures to search for text specified by a user. The text to search is set in the form's Load event procedure. The Click event procedure for the Find button (which the user clicks to start the search) prompts the user for the text to search for and selects the text in the text box if the search is successful.
Private Sub Form_Load()
Dim ctlTextToSearch As Control Set ctlTextToSearch = Forms!Form1!Textbox1
' SetFocus to text box. ctlTextToSearch.SetFocus ctlTextToSearch.Text = "This company places large orders twice " & _ "a year for garlic, oregano, chilies and cumin." Set ctlTextToSearch = Nothing
End Sub
Public Sub Find_Click()
Dim strSearch As String Dim intWhere As Integer Dim ctlTextToSearch As Control
' Get search string from user. With Me!Textbox1 strSearch = InputBox("Enter text to find:")
' Find string in text. intWhere = InStr(.Value, strSearch) If intWhere Then ' If found. .SetFocus .SelStart = intWhere - 1 .SelLength = Len(strSearch) Else ' Notify user. MsgBox "String not found." End If End With
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.