Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144

    advancing to new record

    My form has two fields bound to a table. The first field is a CPT cbo and the second is a Dx cbo. The physician will select a CPT and it's respective Dx. He may use the same CPT for several Dx codes for the same patient and visit. Is there a way to customize the code below that would enter the CPT and Dx, but leave the selected CPT in the cbo so the doctor doesn't have to select it over and over again?


    Private Sub cmdEnter_Click()
    On Error GoTo Err_cmdEnter_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_cmdEnter_Click:


    Exit Sub
    Err_cmdEnter_Click:
    MsgBox Err.Description
    Resume Exit_cmdEnter_Click

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Set the Default value of the CBO in the AfterUpdate event of the CBO.

  3. #3
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Not sure what you mean, can you give a little more detail please?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

  5. #5
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Now I'm really lost. You mentioned to put the value at the After event of the cbo, the attached link references putting it behind a command button, so do I modify the add record code or am I putting to the cbo after event?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You put the referenced code in the AfterUpdate event of your ComboBox.

  7. #7
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    ok, here's the problem as I see it if I put it in the cbo after event. There is going to be a button to enter another dx for a selected CPT . . . I get it that this code will carry the CPT to the next dx. But there will also need to be a next record button to advance to a completely new record . . . with the after event in the cbo it won't clear the cpt when it needs to. . . . so:

    1 button will end the cpt for the next cpt (the code above); the next button will need to be programmed to keep the current CPT until the next cpt button is selected.

  8. #8
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    any takers please?

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The user can override any default value.

  10. #10
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    buckwheat - Assuming that the CPT and Dx records are fields on the same table -- and you said table, singular -- Ruralguy has given you the correct answer for your app, and the behavior you have asked for.

    You could provide a "clear CPT default" button on the form, but you don't need to. Your cmdEnter button code is already advancing to a new, completely blank record, and the default CPT will only become "real" when the Doc enters some data either in that field or another. Before that point, the new record doesn't actually exist with any data on it.

    So, the Doc can always change the CPT number to whatever she wants, either before or after entering the new Dx. (Exception - if the Dx combo box is loaded based on the value of the CPT, then cbo selections must be in hte correct order, obviously.

  11. #11
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Hi,

    I'm certain Ruralguy's instructions were correct and I appreciate the time, but since my initial request was for code , I would have no idea what reference code or default code to put in the after event. For the link, how much of the code gets applied? I'm on the site because I am not an expert, so layman's terms is very helpful.

    Regards
    Buck


    Quote Originally Posted by Dal Jeanis View Post
    buckwheat - Assuming that the CPT and Dx records are fields on the same table -- and you said table, singular -- Ruralguy has given you the correct answer for your app, and the behavior you have asked for.

    You could provide a "clear CPT default" button on the form, but you don't need to. Your cmdEnter button code is already advancing to a new, completely blank record, and the default CPT will only become "real" when the Doc enters some data either in that field or another. Before that point, the new record doesn't actually exist with any data on it.

    So, the Doc can always change the CPT number to whatever she wants, either before or after entering the new Dx. (Exception - if the Dx combo box is loaded based on the value of the CPT, then cbo selections must be in hte correct order, obviously.
    Last edited by June7; 06-03-2013 at 11:35 PM. Reason: fix quote tag

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    The example in tutorial suggested button Click event to offer user option to retain the entered value as default for subsequent records. I recommend using either the BeforeUpdate or AfterUpdate event of combobox. You have code from the link, adapt it for your db, use your control name. The code can be even simpler, variable not needed, assumes data is text and not number or date.

    Me.comboboxname.DefaultValue = """" & Me.comboboxname & """"

    Do you know how to create the VBA procedure? In the event property, select [Event Procedure], click the ellipses (...) to open the VBA editor, type code into the procedure.

    Now moving to a new record is a different issue. This can be automatic after entering or tabbing through the last control on form. This is natural behavior of form and no code is needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    buckwheat - Sorry, I should have gone down a level in description of the procedure, as June7 has done. Please let us know if you need any more help on this one. IF not, please mark the thread solved (top of page, under Thread Tools).

    Here's the code that would go behind the AfterUpdate event of the CPT combo box, which I've called cbxCPT for the sake of the example.
    Code:
    Private Sub cbxCPT_AfterUpdate()
    On Error GoTo Err_cbxCPT_AfterUpdate
    
    Me.cbxCPT.DefaultValue = """" & Me.cbxCPT & """"
    
    Exit_cbxCPT_AfterUpdate:
        Exit Sub
    
    Err_cbxCPT_AfterUpdate:
        MsgBox Err.Description
        Resume Exit_cbxCPT_AfterUpdate
        
    End Sub
    Here's the only code that is absolutely necessary - the rest of the above code is the normal practice for error trapping VBA code, and is probably overkill for this particular event.

    Code:
    Private Sub cbxCPT_AfterUpdate()
    
    Me.cbxCPT.DefaultValue = """" & Me.cbxCPT & """"
    
    End Sub

  14. #14
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Hi,

    Yes, I can put VBA code to events . . . sometimes gets tricky reasoning which event to use.

    I'm guilty as well for assuming everyone knew what I was doing with my form, so, I apologize for not explaining better. Here goes:

    My main form has a cbo (which will be changed to a list box later). Users select a patient's name and demographics for that patient populate in a subform. The CPT and Dx cbo are in another subform. These are the only two fields the doctor needs to populate, demographics, CPT and Dx control source is a master table to generate reports.

    So, when I put the code in the CPT box, I can see it carries to the next record, BUT it also carries to the each patient selected from the main patient cbo box . . . it needs to clear out when a new name is selected; this is why I thought I needed code.

    Thanks for your patience.

    Quote Originally Posted by June7 View Post
    The example in tutorial suggested button Click event to offer user option to retain the entered value as default for subsequent records. I recommend using either the BeforeUpdate or AfterUpdate event of combobox. You have code from the link, adapt it for your db, use your control name. The code can be even simpler, variable not needed, assumes data is text and not number or date.

    Me.comboboxname.DefaultValue = """" & Me.comboboxname & """"

    Do you know how to create the VBA procedure? In the event property, select [Event Procedure], click the ellipses (...) to open the VBA editor, type code into the procedure.

    Now moving to a new record is a different issue. This can be automatic after entering or tabbing through the last control on form. This is natural behavior of form and no code is needed.

  15. #15
    buckwheat is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2013
    Posts
    144
    Hi Dal,

    No need to apologize. Thanks for the code. Can this be modified to accommodate the condition outlined in my last thread?

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  2. Advancing Date with a command button
    By rmd62163 in forum Access
    Replies: 10
    Last Post: 01-29-2013, 05:02 PM
  3. Replies: 2
    Last Post: 12-21-2012, 01:57 PM
  4. Replies: 3
    Last Post: 08-26-2012, 10:04 PM
  5. Within form, advancing to next record
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 08-07-2011, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums