Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2005
    Posts
    7

    Question Unanswered: Need form properties to be set by VB

    I have a form that I want to use to display information to the user while they navigate the database. It's a simple form. It has 2 fields, a label and navigation buttons that I created on it. Can Visual Basic set the following properties of the form as follows?

    1. Always stay on top
    2. Allow other windows (tables, forms queries, etc.) to be active windows behind it
    3. No border
    4. Allow user to display form with shortcut key
    5. Change color based on the value in Color field for current record. (I don't know what values to enter, but I want to control the color of the form this way.)


    There will be several forms like this in the database.

    Suggestions or links to resources that can help me will be greatly appreciated.

    Thank you in advance for your consideration,
    DJ (VB Newbie)

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    1. Always stay on top

    Set the Form's Pop Up Property to Yes and the Modal property to No


    2. Allow other windows (tables, forms queries, etc.) to be active windows behind it.

    They will be if you do Item 1. See below as to how to reference them.


    3. No border.

    Set the Border Style Property to None. Keep in mind though, this will get rid of the Form's (Window) Title Bar and you wont be able to move the form around. You will need to use some Windows API functions to be able to move the form around the screen out of the way of other forms underneith it. Not difficult to do though. Simply copy and paste the following into the Declarations Section of your Form:
    Code:
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    		(ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    		lParam As Any) As Long
    Private Const HTCAPTION = 2
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const WM_SYSCOMMAND = &H112
    Then in the MouseDown event for the Details Section of your Form, copy and paste this code:
    Code:
    ReleaseCapture
    SendMessage Me.Hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    and....there you go.

    If you want a Form title Bar then you will need to set the Border Style property to Thin.

    If you like you can create your own title bar and use the code above within the MouseDown event of the Control you used to make the bar.


    4. Allow user to display form with shortcut key.

    Set the Form's Key Preview property to Yes.
    Then in the Form's On-Key Down event use code something like this:
    Code:
    ' ALT-D
    If Shift = 4 And KeyCode = 68 Then
       MsgBox "ALT-" & Chr$(KeyCode)  ' You can remove this line.
       DoCmd.OpenForm "myFormName", , ,"myCriteria"
    End If
     
    ' CTRL-A
    If Shift = 2 And KeyCode = 65 Then
       MsgBox "CTRL-" & Chr$(KeyCode)  ' You can remove this line.
       DoCmd.OpenForm "myOtherFormName", , ,"myCriteria"
    End If
     
    ' SHIFT-I
    If Shift = 1 And KeyCode = 73 Then
       MsgBox "SHIFT-" & Chr$(KeyCode)  ' You can remove this line.
       DoCmd.OpenForm "myOtherFormName", , ,"myCriteria"
    End If
     
    ' And so on...and or any other way you may want to handle the key codes.
    ' Keep in mind,
    ' When Shift = 1 the SHIFT key is pressed. 
    ' When Shift = 2 the CTRL key is pressed.
    ' When Shift = 4 then ALT key is pressed.

    5. Change color based on the value in Color field for current record. (I don't know what values to enter, but I want to control the color of the form this way.)

    Now, this depends upon whether the color field you are talking about is located within Navigation Form or a Form displayed benieth it. And, I'm not sure if it's the Navigation Fform color you want to change or the Form beneith it (if you know what I mean).

    In any case, I'm going to assume you want to change the color of the Navigation Form based on a color located within a record that is housed in a opened Form. You can reference the Form and Field items this way:
    Code:
    Form_myNavigationFormName.BackColor = Form_myOpenedForm.myColorFieldName.BackColor
    Keep in mind...referencing a Form in this manner only works in VBA code. You can even directly reference controls in a SubForm or muti nested SubForm in this way. For example:

    If you have a Form named Form1 and within Form1 is a SubForm named SubForm1 and within SubForm1 is a TextBox named Text1. You can then directly reference TextBox in the SubForm via code in this way:

    Form_SubForm1.Text1

    Simple as that. There you go....Hope it helps.

    Good luck with your project.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Oct 2005
    Posts
    7
    This is great. Thank you very much for taking the time to answer my questions. I've had time to implement most of your suggestions and it's going very well.

    Another question, if I may... My subform is a continous form. The height of my text box (memo type) is like 4 or 5 rows. But all of my entries aren't using all 4 rows. Can I make the box shrink to fit the number of rows of text so I can eliminate the unused space on the form?

    This is awesome. I am so excited! Thanks again.
    DJ
    Last edited by djl0525; 10-15-05 at 03:35. Reason: grammar

  4. #4
    Join Date
    Oct 2005
    Posts
    7
    The form will be used in 2 ways.
    1. I will open the form for data entry.
    2. The user will open the form to view data.

    I can't seem to find a way to open the form for viewing only. I want to disable all navigation in the form so you cannot click any object on the form and you cannot tab through them. You just look at it and click the Next button.

    Once I know how to do this I'll make a separate copy of the form for users to open.

    Can you please point me in the right direction here?

    DJ

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    Quote Originally Posted by djl0525
    Another question, if I may... My subform is a continous form. The height of my text box (memo type) is like 4 or 5 rows. But all of my entries aren't using all 4 rows. Can I make the box shrink to fit the number of rows of text so I can eliminate the unused space on the form?
    Try playing with the Can Grow and Can Shrink properties.

    The form will be used in 2 ways.
    1. I will open the form for data entry.
    2. The user will open the form to view data.

    I can't seem to find a way to open the form for viewing only. I want to disable all navigation in the form so you cannot click any object on the form and you cannot tab through them. You just look at it and click the Next button.
    What you could do I suppose is this for opening your form(s):

    DoCmd.OpenForm "myFormName", , , , acFormReadOnly, , "No Nav Buttons"

    The acFormReadOnly opens the named form for Read Only. This means that the user can not edit or modify records.

    The "No Nav Buttons" is just a string we pass along into the OpenArgs propery of the form we want to open. Then in the in the form we open (ie: myFormName) we would place this sort of code into the Form's OnOpen event:

    If Me.OpenArgs = "No Nav Buttons" Then
    Me.NavigationButtons = False
    End If


    Simple as that...


    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  6. #6
    Join Date
    Oct 2005
    Posts
    7
    Is there some trick to the Can Grow and Can Shrink properties? I set them both to yes for the memo field in question and it ain't shrinking or growing. It's a shame too, 'cause I'm wasting valuable space on the form.

    Any suggestions on what I might be missing?
    DJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •