02. april 2004 - 23:56Der er
31 kommentarer og 1 løsning
Markere tekst i 4 textboxe ved tryk på en knap + mere
Hej Alle.
Jeg har en Access form, hvorpå der er 4 textbox'e. Det jeg gerne vil er at når man trykker på en kommandoknap, så bliver teksten i disse 4 textbox'e ALLE makeret på en gang, og herefter skal der simuleres at man trykker på <ctrl> + højre musseklik.
Det er fordi jeg har en label printer, hvor man kan gøre følgende:
Lad os sige at man har skrevet en adresse i et word doc, og man herefter markere teksten med musen så den bliver sort, hvis man herefter holder musen hend over den markerede tekst, og trykker <ctrl> + højre musseknap ned, bliver teksten automatisk ført ind i label printer programmet, hvor man så bare kan trykke print. dette vil jg gerne have til at virke i min Database, så når jeg på en form har vist en adresse fra databasen i de 4 textbox'e, og trykker på en kommandoknap, så bliver de 4 texbox'ene makeret og der bliver simuleret <ctrl> + højre musseklik.
Hvorfor benytter du ikke Access' Guide til etiketudskrivning? Hvis du kun vil udskrive een enkelt adresse, kan du gøre det fra en formular. Hvis du vil udskrive alle eller en begrænset del af dine adresser kan du også gøre dette. Udelukkende et spørgsmål om kriterier.
Det skal IKKE være en rapport, det skal være på den samme form som man indtaster daterne i, derfor har jeg valgt at det skal gøres på den måde som er beskrevet ovenfor, er der nogen der kan hjælpe med det ??
Christian and I correct in saying that this feater "<ctrl> + højre musseklik" is available only because there is some software installed on your PC? It isnt a standard feature in windows is it? and if it isnt then I dont think it is anything you can make use of in Access. In Access you cant select text in four differenet fields at once, unless they are in the same record, but it is the record which is selected and NOT the text!
So a quick answer to your quetsion is it isnt possible!
YES you are right about the "<ctrl> + højre musseklik" that is a feature of the labeprinter SW, so if you are in let's say word, and you select some text, and the do the "<ctrl> + højre musseklik" it will automaticlly open up the labeprinter SW and put in th selected text in the right way.
Isn't there a whay to show 4 different records in textbox or listbox or what ever like this, and then select it.
IK, I dont know ANYTHING about how your printer works, but if you "<ctrl> + højre musseklik" in one field in Access does it work? If it does work then you could make a seperate field containing the text from other other foure fields and then use this field for printing your lable.
I dont know how you are getting the data into the four fields but lets say you have an extra field. When you press on the button you could copy the values from these foure fields into the new field with some code similar to this. The code is in the buttons On Click event.
It does work in access when i select a field and then do the "<ctrl> + højre musseklik" it then opens up the label SW and then insert the selected text.
Do you have a form which uses data from a table, or do you enter the data directly into the four fields?
In BOTH cases you need an extra field (unbound) and a button on the form. Do you have any programming experience? If not then now is the time to learn :o)
I can have a look at the dB if you send it to NOSPAMeksperten@santhell.dkNOSPAM
I'm not quite sure how to simulate a right mouse button click, I'll look into that and get back as soon as possible but place this code in the buttons on click event. It selects all of teh text.
Public Enum enButtonToClick btcLeft btcRight btcMiddle End Enum
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _ ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, _ ByVal dwExtraInfo As Long)
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const KEYEVENTF_EXTENDEDKEY = &H1 Public Const KEYEVENTF_KEYUP = &H2
Public Function Ctrl_Down() keybd_event vbKeyControl, 0, 0, 0 End Function
Public Function Ctrl_Up() keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0 End Function
Public Function MouseFullClick(ByVal MBClick As enButtonToClick) As Boolean Dim cbuttons As Long Dim dwExtraInfo As Long Dim mevent As Long
Select Case MBClick Case btcLeft mevent = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP Case btcRight mevent = MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP Case btcMiddle mevent = MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP Case Else MouseFullClick = False Exit Function End Select mouse_event mevent, 0&, 0&, cbuttons, dwExtraInfo MouseFullClick = True
End Function
Now in the buttons On Click event add this code AFTER where you select the text
It allmost works, the only thing that is missing now is that I need to simulate that the right mouse click is done over the new textbox, can this also be solved the 100 point is yours ;-)
This is the bit I cant test as I dont have your printer or software?
The code I have given 04/04-2004 14:50:01 is used to simulate the Ctrl down (Ctrl_Down) Then right click (MouseFullClick btcRight) and then finally Ctrl up Ctrl_Up
But I have NO WAY to test that this works as you want it to. I can see that the code DOES work, but only with the program I have.
Jeg kan også se at koden virker, men jeg kan også se at "højre musseklik" bliver udført over kommandoknappen, og IKKE over den "nye" textbox som vi har lavet. Det vil jeg gerne have ændret således at man får simuleret "højre musseklik" over den nye textbox, hvis dette kan ændres virker det 100%
Nej Nej Christian, dit engelsk er rigtig godt, men det er måske nemmer ikke? :o)
Mmm! I must admit I'm not at all sure how to go about this last bit! Why do things always end up more complicated that first anticipated?
I only thought that it was necessary to select the text and then Ctrl+Right mouse click. But now the mouse has to be over it!
Everything is possible and I am sure this is too but there is quite a bit of work involved and I am pushed for time. The problem is finding out where the text boxes is and also where the actual text is. Then moving the mouse over it, all in code! Not easy but as I said it is possible.
As I said Christain, I am sure it is possible but I just dont have a solution which I can give without quite a bit of work. The problem as I see it is moveing the position of the mouse FROM over the button TO over the selected text. This means finding out where the text box is and then moving the mouse cursor to that position. It may in fact be quite simple, but it isnt someting I do every day, so I would need to play around until I found a solution, and I know that I can end up using hours!
When I say "Finding out where the txt box is" It isnt just a case of saying that the window is at a given position. This position can change! The window in which the text box is placed can be moved or resized for example. So it has to be done every time the code is executed.
I have "solved" the problem, in a VERY PURE WAY, but it works, and the DB is only for my own use, so it is OK for now. What I have done is, that I know that the DB form always opens up in the same place of the screen, so I have just found the X, Y cordinates for that position, at then used the Setcursorpos API to move the cursor to that place and then preform the "højre musseklik". But it also means that I can't hide the "new" textbox, if I do, "your code" can't select it (yet another thing to solve).
I would still like to know the right way to do it, but maybe I can find out if you post the link here.
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.