Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Posts
    20

    Unhappy Unanswered: Annoying issue combo box focus

    Hello,

    I am building an access database for claims tracking. I have a combo box where if the correct code is entered a message will display in a textbox to correspond with the code. However if a wrong code is entered, i want focus to go back on the combo box so the employee can select or type the correct code. Here is what the basic code looks like. Keep in mind that setfocus is doing nothing for me in this case. It just lets the cursor go to the next field.

    This is in the afterupdate event procedure in access:

    if combo = "100" then
    text = "dkajfsdkjafjdk"
    elseif combo = "300" then
    text = "abcdefg"
    else
    combo.setfocus
    msgbox "You must enter a valid code!"
    end if

    This is not setting focus back to my combo box. I have no clue what to do. Is this even possible to do with access or should I go buy VB studio?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Simple solution.......In this case get rid of the Combo.SetFocus statement and place the code into the Before Update event instead of the After Update event. Simply replace the Combo.SetFocus with Cancel = True. Like this:

    Code:
    Private Sub Combo_BeforeUpdate(Cancel As Integer)
       If Combo = "100" Then
    	  Text = "dkajfsdkjafjdk"
       ElseIf Combo = "300" Then
    	  Text = "abcdefg"
       Else
    	  Cancel = True
    	  MsgBox "You must enter a valid code!"
       End If
    End Sub
    On another note....please tell me your ComboBox is filled with data from a table and you are not actually running everything through conditional statements as you've shown in your sample code.....

    It appears to me that code numbers are related to specific text messages. If these codes and related messages are held within a table then if the wrong code number is entered (which means it's not in the List) then the Not In List event can be fired which simply displays your "You must enter a valid code!"
    message. Cleaner....easier....better.

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


  3. #3
    Join Date
    Nov 2005
    Posts
    20

    Thank you

    This worked perfectly. May I utilize you for another question? Upon making any change to a single record in access, I want the date to be stamped on the record, and the employee be prompted to save it.

    Is there an easy way to do this. I'm not even sure where to put this code. Again, this is in access.

    If you can help I'd appreciate it. I am still learning.

    R

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Create two more fields in your table (if you haven't already got them) in the following format:

    EmployeeName (Text Type) ' for the employee name working on the record.
    LastModified (Date Type) ' The date the record was modified.

    Place two textbox fields onto your Form and bind each one to the items above. Make sure the textboxes are named the same as the names you used in the table. Set the Visible property for these two textboxes to No.

    In the IsDirty event for your Form place code that might be something like this:

    Code:
    Me.EmployeeName = whatever you are using to achieve who is on the database...
    Me.LastModified = Now() ' This provides the date and time of modification.

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


  5. #5
    Join Date
    Nov 2005
    Posts
    20
    I don't have an isdirty event, just a dirty event. I don't think this is working. Thanks!

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    VERY sorry...the event is named OnDirty. If you do not have this event for your Forms then please let us know what version of Access you are using.

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


  7. #7
    Join Date
    Nov 2005
    Posts
    20
    Im using office xp and i just have a dirty event...this is frusturating lol

Posting Permissions

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