Results 1 to 4 of 4
  1. #1
    LadyLyke is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    14

    Creating a button that would automatically add 3 fields each time it is selected

    In my database I have a section called days of service which also includes 3 lines for a hospital stay where line 1 is the date the client entered the hospital, the line 2 is the date they left the hospital and the line 3 automatically calculates the difference between the two dates. The reason I need the button is because some of our residents will frequent the hospital but others do not and I didn't want to put X amount of instances of the hospital stay since not all residents will need it. I tried creating a button that when selected it will automatically add those same 3 boxes again to the same form but I keep getting this error and I have no idea what it means or how to fix it. Any help would be greatly appreciated. Thank you



    "The expression On Current you entered as the event property setting produced the following error: Ambiguous name detected: ComboAddStays_AfterUpdate.

    *the expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].


    *There may have been an error evaluating the function, event or macro


    This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs."

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't think you really mean you want to add 3 fields each time the button is clicked. That would mean modifying the table structure "on-the-fly".
    add those same 3 boxes again to the same form
    Again, modifying a form at run time is not a good idea.

    If I understand correctly, you want to add 2 record, entered date and left date (the difference is calculated and shouldn't be stored), when you click the button.
    An insert query would do what you want. The code depends on your table structure. Do you have a table of clients (patients) and a table of "Hospital Stays"?

  3. #3
    LadyLyke is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    14
    I have a table titled Days of Service which includes the clients ID and their hospital stays. What is an insert query? Would that automatically cause the sections I need to be added to the same form again, if needed?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Being Picky... Forms display data. Tables store data.

    An insert query (append query) adds records to a table.

    Lets say you have a form ("frmClient") open, and a client is selected. The "clientID" text box (Not visible) = 100.
    You have a button named "AddStay". The code on the click event would be something like

    (warning: untested code)
    Code:
    Sub AddStay_Click
           'insert new entered record
           Currentdb.Execute "INSERT INTO Days_of_Service (ClientID, StayDate, StayType) VALUES (" & Me.clientID & ", #" & Date() & "#, 'Entered')", dbfailonerror
       
          'insert new discharged record without a date
          Currentdb.Execute "INSERT INTO Days_of_Service (ClientID,  StayType) VALUES (" & Me.clientID & ",  'Discharged')", dbfailonerror
    End Sub
    There could be more code to check if you really want to add the records, if there is already a record for the client for the same date or an entry date without a discharge date.

    ---------
    I made up names - don't know your object names.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-19-2013, 04:09 AM
  2. Replies: 3
    Last Post: 09-19-2012, 11:40 AM
  3. Replies: 7
    Last Post: 08-04-2011, 07:49 PM
  4. Replies: 7
    Last Post: 06-14-2011, 10:37 AM
  5. Replies: 1
    Last Post: 08-17-2010, 02:33 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