Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Unbound fields

    I have a form with 4 unbound fields: cboEmployeesID, cboSupervisorID, cboShiftID, txtWorkDate. When I click to add a new record, I want these fields to remain with the information the same except for cboEmployeesID. This is the code I used. It makes all my fields blank:

    DoCmd.GoToRecord , "", acNewRec


    Me.cboEmployeesID = Null
    DoCmd.GoToControl "cboEmployeesID"

  2. #2
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    The values should stay the same unless you change or delete them.

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That's what I thought too. They all go blank.

  4. #4
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    GoToRecord, , Next,
    Me.cboEmployeesID = Null
    DoCmd.GoToControl "cboEmployeesID"

    Try This

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Are the other controls dependent on another one, i.e. do the combos cascade and the text is calculated - thus the others go blank because you change the first one in the chain? As already stated, the contents of an unbound control shouldn't change just because you go to a new record. Or maybe you are doing a form or control requery/refresh on an event such as OnCurrent?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The code on my OnCurrent is why the unbound fields go blank. I'm probably approaching the problem wrong. This is what I'm trying to accomplish. I'm entering employees daily stats. The stats go onto 1 table. I have 4 unbound fields that I use to populate the fields on the table. What I did was added the code to After Update; Me.EmployeesID=Me.cboEmployeesID, and the rest are the same. Those fields that need to be populated will be hidden. The reason for this is so that the user doesn't have to keep repopulating each field. He only has to enter the name of the employee. The supervisor, date, and shift will stay there. In order to be able to see each field in the unbound fields as you do a search, I made a code in the OnCurrent; Me.cboEmployeesID=Me.EmployeesID. It works great until I try to add a record. The fields go null and the unbound fields do what I told them to do and go null. Like I said, I'm probably approaching the problem wrong. Fresh ideas are welcome.

  7. #7
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The code; "GoToRecord, , Next," Gave me an error

    Click image for larger version. 

Name:	Error.jpg 
Views:	14 
Size:	52.5 KB 
ID:	38045

  8. #8
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Sounds like you could just use an unbound form and use an insert query to enter data. Then just set those controls you need null to null

    edit: That error looks like its from the extra "," after "Next"

    Another edit: You could also put the code me.cboemployees = me.EmployeeID and the others in the click event of the command button you are using to save the record.

  9. #9
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Use an insert query? I'm not familiar with that one.

  10. #10
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    An Insert query is known as an Append Query.

    That error you get is because of the extra "," (Typo)

    Why do you use Two Error traps.

  11. #11
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    If you were to use an unbound form you could have code under a button to execute an insert.

    Code:
    Dim strSql as string
    
    strSql = "Insert into YourTable(EmployeeID,SomeField,SomeOtherField) Values (" & me.cboEmployeeID & "," & me.anotherControl & "," & me.AnotherControl2 & ")"
    Currentdb.Execute strSql, dbFailOnError
    
    ' then set controls to null
    
    me.somecontrol = null
    But I think what you may need to do is move the Me.EmployeeID = Me.cboEmployeeID to your save command as in my second edit above..

  12. #12
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    [QUOTE= He only has to enter the name of the employee. The supervisor, date, and shift will stay there. [/QUOTE]

    Why not put these controls in a form header. The sub form would be where you add records.

    That error you get is because of the extra "," (Typo)

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Stepping back a bit - why is the form unbound?? Even if you wanted to keep certain values from the previous record I suspect you could use the default value property. Unbound forms require more code than bound forms, and if there isn't a good reason to do so, then it doesn't make sense to trouble yourself with all the extra work.

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The form is bound to a table.

  15. #15
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    The root of the problem your having is that you are setting the value of the UNBOUND control (Me.cboEmployeeID = Me.employeeID) in the on current event. When you go to a new record, The current event fires and your code runs and sets the combo to null. It probably should be Me.EmployeeID = Me.cboEmployeeID in the command button (note its reverse of what you had)

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

Similar Threads

  1. Too many Unbound sum fields
    By tagteam in forum Forms
    Replies: 5
    Last Post: 04-17-2017, 02:59 PM
  2. Populate Unbound Fields on Report
    By RyanP in forum Reports
    Replies: 6
    Last Post: 06-24-2015, 08:12 PM
  3. Replies: 8
    Last Post: 08-02-2012, 10:50 AM
  4. Saving bound and unbound fields
    By mejia.j88 in forum Forms
    Replies: 2
    Last Post: 11-04-2011, 05:09 PM
  5. Count and Sum of unbound fields?
    By C90RanMan in forum Forms
    Replies: 0
    Last Post: 07-29-2010, 01:17 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