Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2013
    Posts
    18

    Unanswered: Whats Wrong With My Code?

    Option Compare Database
    Option Explicit

    Private Sub SaveRecord_Click()

    ' Declare variables for the Database and Tables(Recordset)
    ' We are using DAO(Data Access Objects)
    Dim db As DAO.Database
    Dim rstOne As DAO.Recordset
    Dim rstTwo As DAO.Recordset

    ' Set the variables to the current database in use and tables
    Set db = CurrentDb()
    Set rstOne = db.OpenRecordset("T_EMPLOYEE")
    Set rstTwo = db.OpenRecordset("T_EMPLOYEE_INFO")

    Dim strSQL As String

    With rstOne

    rstOne.AddNew
    !LanID = Me.UserID
    !FirstName = Me.FirstName
    !MI = Me.MI
    !LastName = Me.LastName
    !Suffix = Me.Suffix
    !EMail = Me.EMail

    rstOne.Update
    End With

    rstOne.Close

    With rstTwo

    rstTwo.AddNew
    !LanID = Me.UserID
    !NRCOffice = Me.NRCOffice
    !Division = Me.Division
    !Branch = Me.Branch
    !SubBranch = Me.SubBranch
    !Title = Me.Title
    !PayPlan = Me.CboPayPlan
    !Grade = Me.CboGrade
    !WorkLocation = Me.Room
    !Phone = Me.Phone
    !EmplInfoStatus = Me.CboEmp


    rstTwo.Update
    End With

    rstTwo.Close

    End Sub



    The rstTwo.Update keeps getting highlighted saying Index or Primary Key Cannot Contain a Null Value...Please Help i Dont Know why this error messege keeps coming up?

  2. #2
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    what is the primary key in T_EMPLOYEE_INFO?

    are there other required fields in T_EMPLOYEE_INFO? if so, what are they?

  3. #3
    Join Date
    Jan 2013
    Posts
    18
    The Primary Key Field Is Not on The Form..Would the primary key have to be on the form in order for the data to be updated into the table? The Name of the primary key field is EI_ID. And theres no other required fields

  4. #4
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    is EI_ID an autonumber field, if not what type of field is it?

  5. #5
    Join Date
    Jan 2013
    Posts
    18
    The type Is TextBox. Should it be Autonumber?

  6. #6
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    what is the data type for EI_ID in the table?

    You're not passing a value to the table for EI_ID, which is the primary key. If the data type is not autonumber, then that is most likely the problem and you'll need to include the value for EI_ID in the update.

  7. #7
    Join Date
    Jan 2013
    Posts
    18

    Thanks

    Thanks Alot man!! i Finally fixed the problem. It was exactly what you said it was. Thanks Again

Posting Permissions

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