Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Messages/Set colors during forms activities

Status
Not open for further replies.

torf66

Programmer
Jun 10, 2003
43
0
0
US
Is there a way to only have this message display when they try to enter something into the numAdmitNumber? When I tab or hit enter to go to the next field on the form the message "No Changes Possible" displays. Which they have not really entered anything new into the field but they are just tabbing or entering down to the next field on the form.

This is what I have in the On Key Down event procedure:

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If numAdmitNumber.Locked Then
MsgBox "No changes possible"
End If

Also when I first come into the form the field for numAdmitNumber is now greyed out but when I tab down or enter down to the next field the colors go away. Is there a way to keep the colors gray for the field numAdmitNumber no matter what field I am on in the form. The Grey background for the field numAdmitNumber only displays when I click back on the field. I want it to stay grey all the time when there is a value in the field. Another issue is when I go to the next record and that record displays the field numAdmitNumber is not grayed out even though there is a value in the field.
Thanks,
Todd
 
it's doing exactly what you are asking it to do. instead of putting code into the OnKeyDown event, i'd put it on the OnEnter event. then they can't even type anything if the box is locked. another option--one that would help the user--is to have perhaps the text or the background color of 'locked' objects be red or something, so they know to not even bother trying.

2) what is making your text box grey? what programming have you done to do that? have you tried conditional formatting? why/when do you want it greyed out? what's your business rules? when there's something in it, it's LOCKED and GREY? if you have some code that makes it grey, where is this code? what event?
 
Here is what I have in the properties for the field numAdmitNumber. When I display the form at the first record the numAdmitNumber is grey becuase there is a value in the field of the first record. Red or grey, grey is easier on the eyes. I want the field to stay grey even when they go to the next field on the form right now when they go to the next field then the numAdmitNumber does not have a grey background it goes to white. I want it to stay grey so that they now it is a locked and nothing can be entered into that field.

How would I put in the logic I have below for the On Key Down into the On Enter?



This is what I have in the On Got Focus:
Private Sub numAdmitNumber_GotFocus()
numAdmitNumber.Locked = Not NewRecord
End Sub

This is what I have in the On Key Down:
Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If numAdmitNumber.Locked Then
MsgBox "No changes possible"
End If

End Sub

This is my colors settings in the properties for
the form under On Current:
Private Sub Form_Current()

If numAdmitNumber.Locked Then
numAdmitNumber.BackColor = 16777215
numAdmitNumber.ForeColor = 0
Else
numAdmitNumber.BackColor = 12632256
numAdmitNumber.ForeColor = 0
End If



End Sub


 
Another issue I have when I go to the next record the field for numAdmitNumber does not stay grey it loses the color and show as a white background even though there is something in the field. How do I get it to stay grey all the time when I navigate between records that exis?
 
you have your code in the wrong events. seems like you need to become a little more familiar with each event and when it fires. OnFocus of your text box fires after the OnCurrent event of the form, so you text box is not getting locked before the color changes.

i would get the code out of the OnFocus event. In HELP it says to use the NewRecord property in the OnCurrent event of the form.
In your OnCurrent event i would put the code from the OnFocus event first, before the existing OnCurrent code.

Code:
    If Me.NewRecord Then
        numAdmitNumber.Locked = True
        numAdmitNumber.BackColor = 16777215
        numAdmitNumber.ForeColor = 0
     Else
        numAdmitNumber.Locked = False
        numAdmitNumber.BackColor = 12632256
        numAdmitNumber.ForeColor = 0
    End If

so try that and see if it helps.






 
One other issue I am having is when I tab to the next field or enter to the next field the grey in the box for numAdmitNumber loses the grey, it does not stay grey. In what event do I need to put code so that it will stay grey the whole time I am in a record and entering info into other fields?

Thanks,
Todd
 
does this still happen even after you change all the code i wrote above?
 
Yes if I go to a new record the field numAdmitNumber stays grey but if I tab down to the next field in an existing record then the field loses the grey and goes to white background on numAdmitNumber.
Here is what I have in the events:

Private Sub Form_Current()

numAdmitNumber.Locked = Not NewRecord

If Me.NewRecord Then
numAdmitNumber.Locked = True
numAdmitNumber.BackColor = 16777215
numAdmitNumber.ForeColor = 0
Else
numAdmitNumber.Locked = False
numAdmitNumber.BackColor = 12632256
numAdmitNumber.ForeColor = 0
End If



End Sub

----------------------
This is what I have in the properties of the field numAdmitNumber's Got Focus

Private Sub numAdmitNumber_GotFocus()
numAdmitNumber.Locked = Not NewRecord
End Sub






There is no code in the On Focus event.
 
get rid of the code in the text box's GotFocus event
get rid of the first line of code in the OnCurrent event
 

IF I remove this then the user can enter something into the field when they should not be. If you are on a record that has something in the numAdmitNumber field and they try to enter something over it then if I remove the GotFocus logic then my message in they KeyDown does not display. I want the numAdmitNumber locked down if there is something entered into it.

Question I have is there a way when I add a new record then if I make a mistake on the numAdmitNumber and try to enter over the number say for example I enter 123 then tab to the next field and I see the numAdmitNumber should have been 321 right now as my logic sits if I go back up to that numAdmitNumber and try to change it the message 'No Changes Possible' displays. I do not want this to display when they are entering a new record into the database. How do I set that on a new record?


Private Sub numAdmitNumber_GotFocus()
numAdmitNumber.Locked = Not NewRecord
End Sub

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If (Not IsNull(numAdmitNumber)) And (KeyCode >= 32) And numAdmitNumber.Locked = Not NewRecord Then
MsgBox "No changes possible"
End If
End Sub
 
Maybe I'm missing the point here, but it seems this has become unnecessarily complex. The object is, if it's a new record, numAdmitNumber can be edited. If it's not a new record, numAdmitNumber should not be editable, preferably grayed out. Have I got that right? If so, why not this:

Code:
Private Sub Form_Current()
If Me.NewRecord Then
     Me!numAdmitNumber.Enabled = True
     Else
          Me!numAdmitNumber.Enabled = False
End If
End Sub

If it's a new record, the field is enabled and will display and behave normally. It it's not enabled, it will be grayed out and cannot be tabbed into. No msgbox or user interaction needed. Please pardon if I've misunderstood the issues.

Ken S.
 
Eupher--
i agree. same thing i did above but with LOCKED instead of ENABLED. torf66 you do not have to keep going on with the OnFocus and OnKeyDown stuff. The form's OnCurrent event will take care of everything for you. Again--just put in the OnCurrent event this code (or Eupher's code), and nothing else, believe us ok? (sorry i switched locked false/true earlier, but the essence of the code and the need for you to leave out all other code still holds true):
Code:
Private Sub Form_Current()
If Me.NewRecord Then
    numAdmitNumber.Locked = False
    numAdmitNumber.BackColor = 16777215
    numAdmitNumber.ForeColor = 0
Else
    numAdmitNumber.Locked = True
    numAdmitNumber.BackColor = 12632256
    numAdmitNumber.ForeColor = 0
End If
End Sub

do only this, then test it out.
 
Ok this works great. But I need to have a message display when they try to enter something into this field when there is already something in the field. Where would I put that message then base on your code in the last thread? I need to display the message 'No Change Possible'

Thanks,
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top