Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50

    Using command button to carry data into a form

    I currently have an Access database with two tables, one with a list of patients and another with a list of admissions for each patient. Basically what I'm trying to do is select a patient from my current list and add information for a new admission for that patient. I was able to do this using a subform within my main form pretty easily, but the size of the form has become cumbersome.



    What I'm trying to accomplish is to select a patient from a combo box, and then open a "New Admission" form using a command button, which will carry forward the Patient ID from the combo box and allow me to enter data for a new admission. Right now, the command button works to bring up the form with the existing admissions for that patient, but when I try to add a new record the Patient ID is lost within the form and it won't let me add any new records.

    I'm obviously missing something, but I can't figure out what it is. If anyone is willing to help me out, I'd greatly appreciate it.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Use the OpenArgs argument of the OpenForm command: http://www.baldyweb.com/OpenArgs.htm

  3. #3
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    Thanks for the help! However, I'm not familiar with adding Visual Basic code to an Access database (I do understand the code itself). Can I enter the OpenString code somewhere into the Event Procedure, or do I have to somehow using the Visual Basic editor?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What do you have behind the current button used to open the next form?

  5. #5
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    All I have right now is what the wizard creates to open a new form and select certain data. Here's the Event Procedure:

    OpenForm
    Form Name: frmAdmission
    View: Form
    Where Condition: ="[PatientID]=" & [cmbPatientSelect]

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Start by converting that Macro to code: http://www.btabdevelopment.com/ts/de...aspx?PageId=91

  7. #7
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    That doesn't do anything...when I open Visual Basic I now have the ACWZTOOL project listed under the project window, but I can't expand my database (there's no forms to select).

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hmm...can you zip up your db and post it?

  9. #9
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    Unfortunately, no because it contains protected patient data, and I'd lose about 20 hours of work by deleting the tables with the patient info.

    Is there a way in the Visual Basic editor to add forms to the project? It seems very, very constrained if you can't...

  10. #10
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    Nevermind, answered my own question...I'm going to try just adding the code into the VB editor, my only question will be how to add code that would simulate the code built by clicking on the command button.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Import your db into a new db but on the table tab select advanced and *only* import the structure and not the data. http://www.btabdevelopment.com/ts/impnew
    zip up what you have and post it. Taa...Daa!

  12. #12
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    Hah, don't know why I didn't think of just saving the db under a different name and deleting the data.

    Thanks for the help! frmMain contains the command button "New Admission", frmAdmission is the form I'd like to have open with PatientID being passed to allow adding a new record for the patient tied to that ID.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The frmMain has no RecordSource so from where do you expect the get the PatientID?

  14. #14
    cardgage is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    50
    I was trying to make it so the patient is selected using the combo box on frmMain, then carry the selected PatientID into frmAdmission. I wanted to keep frmMain unbound because eventually I'll need to add more functionality to it once my clinic opens up.

    Of course, if there's a better/easier way I'd be happy to hear any suggestions.

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    D'oh...of course you were. I'm working too many things at the same time right now, sorry. You cound set it up so that you only use the ComboBox. A new name would Open frmPatientInfo first and then frmAdmission otherwise just go directly to frmAdmission. I'll impliment the Admission button first and let you look at it.

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

Similar Threads

  1. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 PM
  2. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Export Command Button in Form
    By jjmartinson in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 01:28 AM
  5. Adding Command Button To Form
    By uneek78 in forum Forms
    Replies: 7
    Last Post: 03-27-2009, 07:43 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