Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Trouble Adding employees to a form

    In the attached file, I am trying to add personnel using the frmAddPersonnel, In it I will put in the employee's name, first and last, the preferred or nickname and the branch and whether or not they are a branchhead.

    Two things happened.

    1. When I was trying to indicate if they were a branchhead it gave me the choice of yes/no-on/off-true/false. I do not like any of them I just want a box that


    you can put a checkmark in if they are a branchhead and leave blank if they are not.It does not give that choice.

    2. The second it started to number them, employees : PersonnelID, in the 50's. What is going on? It could just add them sequentially. Why make this big jump in numbering?

    I just found out by running frmAddPersonnel a box opens up see attached file that I think is looking for a PersonnelID number when it opens. I gave it one, the PersonnelID number
    was 60. It was just a random choice. Why does it not just number sequentially?

    I just need to correct these two things.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files
    Last edited by Lou_Reed; 05-17-2017 at 10:51 AM. Reason: correction

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    True/false fields CANNOT be null by nature.
    if you want nulls ( blanks) then you must use a String. T,F,or null.

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Is the checkbox option not applicable here?

    Respectfully,

    Lou Reed

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Lou_Reed View Post
    <snip>Two things happened.

    1. When I was trying to indicate if they were a branchhead it gave me the choice of yes/no-on/off-true/false. I do not like any of them I just want a box that
    you can put a checkmark in if they are a branchhead and leave blank if they are not.It does not give that choice.
    Quote Originally Posted by Lou_Reed View Post
    Is the checkbox option not applicable here?
    Yes, but on the form, the control is a text box, not a check box. Delete the control and add the "BranchHead" field again.


    Quote Originally Posted by Lou_Reed View Post
    2. The second it started to number them, employees : PersonnelID, in the 50's. What is going on? It could just add them sequentially. Why make this big jump in numbering?
    The "PersonnelID" field is an autonumber type field. It is guaranteed to ALWAYS provide a unique number, but not a sequential number.
    It is not even guaranteed to be a positive number.
    This is one reason that an autonumber should NEVER be displayed!

    See:
    Autonumbers--What they are NOT and What They Are
    http://www.utteraccess.com/wiki/Autonumbers



    Quote Originally Posted by Lou_Reed View Post
    I just found out by running frmAddPersonnel a box opens up see attached file that I think is looking for a PersonnelID number when it opens. I gave it one, the PersonnelID number
    was 60. It was just a random choice. Why does it not just number sequentially?
    There are several things going on here.

    Why was the parameter dialog box displayed?? It was caused by your code. You tried to reference (requery) a form that was CLOSED! (And by using incorrect syntax at that!)
    The line is
    Code:
    Form_frmPersonnel.Requery
    So, form "frmPersonnel" is open. You click on the ADD button and this code executes
    Code:
        DoCmd.OpenForm "frmAddPersonnel"
        DoCmd.Close acForm, "frmPersonnel"
    Form "frmAddPersonnel" is open and you add the personnel information. You click the ADD button, some code executes and the last line is
    Code:
        Form_frmPersonnel.Requery
    But "frmPersonnel" is not open -remember? It was closed.... but because you used the internal Access name of the form, (bad) magic happens and something on the form needs the PersonnelID value causing the request for the parameter value of PersonnelID.
    So instead of re-querying "frmPersonnel" in the btnAdd code, you should open "frmPersonnel", but in the close event of form "frmAddPersonnel".. (I would add a close button)

    I said you used invalid syntax because "Form_frmPersonnel" is how ACCESS refers to a form.
    You should NEVER use this syntax; you need to/must use the form collections name: "Forms!frmPersonnel".



    A side note: on form "frmAddPersonnel", the tab order of the controls is messed up....
    Also, why is the field "Branch" a Long??? Is there going to be a table of Branch names?

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Why was the parameter dialog box displayed?? It was caused by your code. You tried to reference (requery) a form that was CLOSED! (And by using incorrect syntax at that!)
    The line is

    Code:
    Form_frmPersonnel.Requery
    Where is this code I pointed out above? I cannot easily find it or I just cannot find it.

    I have some questions to ask on it. Once I find it.

    Respectfully,

    Lou Reed
    Last edited by Lou_Reed; 05-18-2017 at 12:18 PM. Reason: correction

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    OK, I have found the code. Everything is ok there.

    Code:
    Why was the parameter dialog box displayed?? It was caused by your code. You tried to reference (requery) a form that was CLOSED! (And by using incorrect syntax at that!)
    But I have a few questions and the first is : how that form frmPersonnel is closed by just inspecting code? It is not apparent to me. I understand that
    you cannot or you should not requery a closed form. But how do you know just by the seat of your pants?

    Code:
    So, form "frmPersonnel" is open. You click on the ADD button and this code executes[
    In here you just assume that the form is now open? Is this for pedagogical purposes here?
    Sort of like let's assume frmPersonnel is open? I just do not follow the steam of logic.

    So I am guessing that I change the line

    Form_frmPersonnel.Requery

    to what? What do I add?

    You also said add a close button and then requery frmPersonnel?

    Is this the way to do things?

    Any help appreciated. Thanks in advance.

    Respectfully,


    Lou Reed

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Code:
    So instead of re-querying "frmPersonnel" in the btnAdd code, you should open "frmPersonnel", but in the close event of form "frmAddPersonnel".. (I would add a close button)


    Explain this line, especially the "I would add a close button". I am not following that logic.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    So, form "frmPersonnel" is open. You click on the ADD button and this code executes

    Code:
        DoCmd.OpenForm "frmAddPersonnel"
        DoCmd.Close acForm, "frmPersonnel"
    At this point frmPersonnel is closed? That makes sense, it is the last executed of the two statements immediately above and that closes frmPersonnel.

    My question is where do these two statements go in the overall code? Where are they placed? It is in the Sub btnAdd_Click(), but just where does it go?

    Finally, where should the close button go? Why do I need it?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Last edited by Lou_Reed; 06-02-2017 at 06:57 AM.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Apologies... your thread disappeared for a while.

    I'll see if I can catch up.....

    I posted (post #4)
    I said you used invalid syntax because "Form_frmPersonnel" is how ACCESS refers to a form.
    You should NEVER use this syntax; you need to/must use the form collections name: "Forms!frmPersonnel".
    Post #5
    Quote Originally Posted by Lou_Reed View Post
    <snip>
    (And by using incorrect syntax at that!)
    The line is

    Code:
    Form_frmPersonnel.Requery
    Where is this code I pointed out above? I cannot easily find it or I just cannot find it.

    I have some questions to ask on it. Once I find it.
    How I found all of the instances of that syntax is:
    Open the IDE.
    Close all of the code modules.
    Open one code module (any module).
    Press <ctl-F> (Find)
    Enter "Form_" (NO quotes)
    Under "Search", click on "Current Project"
    Click on the button "Find Next".
    Keep clicking on "Find Next" until the error message "The specified region has been searched" appears.


    Quote Originally Posted by Lou_Reed View Post
    OK, I have found the code. Everything is ok there.
    Does that mean you have corrected all 30 instances to the correct syntax???

    -------------------------------------------------------------------------------------------

    Post #6
    Quote Originally Posted by Lou_Reed View Post
    But I have a few questions and the first is : how that form frmPersonnel is closed by just inspecting code? Inspecting code does not close forms
    It is not apparent to me. I understand that you cannot or you should not requery a closed form. But how do you know just by the seat of your pants?
    Not by the seat of my pants... I read the code:
    Code:
    DoCmd.Close acForm, "frmPersonnel
    Code that YOU wrote...

    Code:
    So, form "frmPersonnel" is open. You click on the ADD button and this code executes[
    In here you just assume that the form is now open? Is this for pedagogical purposes here?
    Sort of like let's assume frmPersonnel is open? I just do not follow the steam of logic.

    So I am guessing that I change the line

    Form_frmPersonnel.Requery

    to what? What do I add?
    The proper syntax is
    Code:
    Forms!frmPersonnel.Requery
    -------------------------------------------------------------------------------------------

    Post #6
    Quote Originally Posted by Lou_Reed View Post
    <snip>
    You also said add a close button and then requery frmPersonnel?

    Is this the way to do things?
    I suggested adding/having a close button for the form. I have a close form button on every form except the main form. The main form has a "Quit" button.
    This is one of my forms
    Click image for larger version. 

Name:	Form1.jpg 
Views:	62 
Size:	30.0 KB 
ID:	28952



    Looking at your dB, it seems that form management was an afterthought.
    For instance:
    the dB opens and the "DivisionDashboard" form opens. (I never use the switchboard manager -too limiting and it is not even available on my ribbons).
    "DivisionDashboard" is set to Popup and Modal. (2 things I also never use)
    You click on "Personnel Management" and form "frmPersonnel" opens - also Popup and Modal. The dashboard is still visible behind "frmPersonnel".
    Clicking on the ADD button, "frmPersonnel" disappears and only "DivisionDashboard" is visible. If I move "DivisionDashboard", "frmAddPersonnel" becomes visible.
    There are 2 buttons - "Add" and "Done". The name of the button with the caption "Done" is "btnCancel"?? And no control tip text to say "Close form".
    Does "Done" mean go back to the previous or Cancel the current operation??

    On "frmPersonnel", I finally saw a button towards the bottom of the form that says "Close Form".
    All of my forms have a close button in the same location - top right corner of the header. (see image above)
    Consistency - of object placement, colors and names.

    My thought process would be:
    "DivisionDashboard" opens
    Click on a menu option. Click on "Personnel Management", form "frmPersonnel" opens. "DivisionDashboard" closes because it is just a menu.
    Need to add personnel... click in the Add button and "frmAddPersonnel" opens. I would hide (not close) "frmPersonnel". Only "frmAddPersonnel" is visible (maybe might need info off of "frmPersonnel".)
    When done adding personnel, close "frmAddPersonnel" and make "frmPersonnel" visible.
    Clicking on the close button would close "frmPersonnel" and open "DivisionDashboard" -tada! back to the beginning.
    Only one form visible at a time.



    And speaking of "frmPersonnel", why is there a subform of "frmAddPersonnel" at the bottom of the form???

  10. #10
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, thanks I will give it a try. Thanks for your feedback. Please understand, I was quite new to forms requiring opening, closing and requerying so that I why I asked the dumb questions.

    You showed me a new method of find (and replace?) on MS Access 2010. That is very helpful.

    Respectfully,

    Lou Reed

  11. #11
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I will try your suggestions, but first let me ask a dumb question.

    Where do the lines of code;

    Code:
    DoCmd.OpenForm "frmAddPersonnel"
    DoCmd.Close acForm, "frmPersonnel"
    go? My guess is that they are the first executable lines in Sub btnAdd_Click.

    I would put them there, but any other suggestion I would consider.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  12. #12
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Code:
    Does that mean you have corrected all 30 instances to the correct syntax???
    I counted far more than 30. It was morel likely 47 instances.

    Also, can I just use find and replace to replace all instances of Form_, with Forms!. That would be grate if it would work.


    It would save a lot of time.


    Any help appreciated. Thanks in advance.

    Respectfully,


    Lou Reed

  13. #13
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I went ahead and used the find and replace command for VBA code on my project. There are actually 46 instances of Form_. Now I just ran find/replace and
    changed all instances of Form_ to Forms!. That was a bad idea.

    It failed on compile on the following line:


    Private Sub Forms!Load()

    The line was originally :

    Private Sub Form_Load().

    Now that old version works and the new version does not. I am unsure as to why.

    I admit I have not seen online the command


    Forms!Load()

    anywhere, but as you said the old version is not to be used. So what is going on here.

    Any help appreciated.

    Thanks in advance.

    Respectfully,

    Lou Reed

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    That is why I said 30 instances!!

    So what is going on here.
    You should not REFER to FORMS using "Form_"..... This does NOT include FORM events.

    "Form_Open" and "Form_Close" are FORM EVENTs and SHOULD NOT be changed.



    BAD:
    Form_frmPersonnel.Requery

    GOOD:
    Forms!frmPersonnel.Requery


    Required:
    Code:
    Private Sub Form_Open()
    blah  blah
    End Sub
    
    Private Sub Form_Close()
    blah  blah
    End Sub

  15. #15
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I see. I was too quick to jump on what you said. Thanks for he update.

    Respectfully,

    Lou Reed

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

Similar Threads

  1. Replies: 9
    Last Post: 04-06-2017, 02:26 PM
  2. Replies: 8
    Last Post: 12-12-2013, 03:54 PM
  3. No More Than 4 Employees Allowed on Form
    By burrina in forum Access
    Replies: 1
    Last Post: 10-25-2012, 10:54 PM
  4. Replies: 2
    Last Post: 04-16-2012, 12:56 PM
  5. Trouble adding data with forms
    By chuck130 in forum Forms
    Replies: 3
    Last Post: 09-02-2010, 09:57 AM

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