4
Contributors
4
Replies
20
Views
2 Years
Discussion Span
Last Post by milan.oparnica.90
0

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Unload Me
End If
End Sub

Edited by mcdczzz

0

First make sure to set child forms KeyPreview property to TRUE. This will ensure that your Esc key event will be captured by the form.

In the MDI form write something like:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim oFrm As *child_form_name, for exmple Form2*

If KeyCode = vbKeyFx (where x is a numer from 1 to 12) then 
    Set oFrm = New Form2 '...(actualy *child_form_name*)...
    oFrm.Show vbModal,Me

    '...If you unload the form from within it self then you don't need this line, but if you just Hide it then you must:

    Unload oFrm

    '...Finaly release the object...

    Set oFrm=Nothing

End If

End Sub

The Escape key press code stated above is correct except that it is general better idea to unload the form in the calling process.

You can also use vbKeyEscape constant instead of 27.

0

.hi!! Good day.

language: Visual Basic 6.0

I want to know the code for the functions keys as a command for my program (Student Details)..F1 as Add, F2 as Edit, F3 as Save, F4 as Cancel, Del for Delete and Esc as Exit..and a code for running my program on other PC.
Thanks a lot!! :)

0

Well, I'm not sure if I understud your question correctly.

Function keys are not different then other keys. You can pretty much use the same aproach as above mentioned except that you test against vbKeyF1,vbKeyF2... vbKeyDelete and vbKeyEscape.

If you organize your interface in a way that is allows menus too then you can easly attach these keys to menus.

As for running your program on other PC you must use COM+ (formerly DCOM). It is a fairly complex technology you can start your study on Microsoft COM+ MSDN.

Basically it is invoked with the command CreateObject ("object-name","remote-pc-name-or-IP-address). But you have to work alot before you get to this command :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.