Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2009
    Posts
    9

    Unanswered: "Submit Changes" type button.

    Hello,
    I am currently working on a database to track employees for a company. I am trying to make a form which allows the user to add a new employee. The form does work, but not in the way I want. Currently, the form automatically creates a new row in the table the instant you type any value in for the Employee Number (see attached photo). I would like for the form to wait until the user presses the Add Employee button to insert the row or, if they press cancel, throw out the information. Any help would be great, thanks.

    ~C
    Attached Thumbnails Attached Thumbnails AddEmployee.bmp  

  2. #2
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267
    My guess from the picture is that you have the form bound to the employee table. Try using an unbound form and use an SQL insert statement behind your Add Employee button.

    C

  3. #3
    Join Date
    Jun 2009
    Posts
    9
    Awesome! That worked perfectly, thanks!

  4. #4
    Join Date
    Jun 2009
    Posts
    9

    Next problem...

    Now I need to check to see if the Employee number is already in use (i.e. compare it with the table). Any ideas?

    ~C

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I'm thinking Employee Number should be your primary key in the table (No dups allowed). You can then put in: on error goto XXXXX code before your SQL statement that adds the new record. XXXX: would be at the end of the routine which does nothing except closes the recordset (if need be.) along with a message box saying the record could not be duplicated. It would go to the XXXX: label when it errors while trying to update a duplicate Employee Number.

    Otherwise,
    You could also use the dlookup command to see if the Employee Number is already used before the sql statement.

    If dlookup("[EmployeeNumber]","myTable", "[EmployeeNumber] = " & me!EmployeeNumber & "") <> "" then
    msgbox "Number already in the table."

    or
    If dlookup("[EmployeeNumber]","myTable", "[EmployeeNumber] = " & me!EmployeeNumber & "") <> Null then

    or
    You can write code to open a recordset with criteria EmployeeNumber = " & me!EmployeeNumber & "" and see if any records exist in the recordset.
    Last edited by pkstormy; 06-03-09 at 00:54.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Jun 2009
    Posts
    9
    Perfect! Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •