Results 1 to 10 of 10
  1. #1
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352

    Angry Simply Cannot Get Code to Work. Add Form Data to Table. Unbound Boxes.

    I simply cannot get this code to function. I have a form all unbound text boxes and am using coding to transfer the data entered to my main data table. It simply is not working, not sure why. Code posted below, used option explicit for a spelling safeguard. Any help appreciated, thanks.


    Code:
    Sub cmdSubmit_Click()
    On Error GoTo Err_proc0
    
    If IsNull(Me.cboCell) Or IsNull(Me.txtDowntime) Or IsNull(Me.txtRamp) Or IsNull(Me.txtDetail) Or IsNull(Me.txtCause) Or IsNull(Me.txtPart) Then
    MsgBox "Some key field(s) are empty. Please completely fill form before submission."
    End If
    Exit Sub
    
    Dim DE As Object
    Dim PI As Object
    Set DE = CurrentDb.OpenRecordset("tbl_DataEntry")
    Set PI = CurrentDb.OpenRecordset("tbl_PartsInfo")
    
     ' Add data records to respective tables
     
    DE.AddNew
    PI.AddNew
        DE![Cell_Product_FK] = Me.cboCell.Value
        DE![ProductType_FK] = Me.txtProduct.Value
        DE![EntryDate] = Me.txtDate.Value
        DE![Details] = Me.txtDetail.Value
        DE![RootCause] = Me.txtCause.Value
        DE![Downtime] = Me.txtDowntime.Value
        DE![RampUp] = Me.txtRamp.Value
        DE![LaborIncrs] = Me.txtLabor.Value
        DE![PartNumber_FK] = Me.txtPart.Value
    If Me.txtPart = DLookup("PartNumber_PK", "tbl_PartsInfo", "PartNumber_PK =" & Forms![frm_Entry]!txtPart) Then
        MsgBox "Please leave the Description box blank for this submission."
    Else:
        DE![Description] = Me.txtDscrp.Value
        PI![PartNumber_PK] = Me.txtPart.Value
    End If
    DE.Update
    PI.Update
    Set DE = Nothing
    Set PI = Nothing
    Exit Sub
    
    Err_proc0:
        MsgBox Err.Description
        Exit Sub
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    The beauty of Access is , you dont have to write vb code.
    You dont need ANY of this. Have a BOUND form, the user enters data into the bound form, with bound fields, into an entry table.
    zero code.
    Then when finished , run a query to add/ modify / delete data from the MAIN data table.
    1 query, zero code.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You need to remove your On Error GoTo Err_proc0 and see which line is creating the issue. It is probably a type mismatch or Null error.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Note the position of

    Exit Sub

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by pbaldy View Post
    Note the position of

    Exit Sub
    Doh ... I missed that one too.

  6. #6
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Quote Originally Posted by pbaldy View Post
    Note the position of

    Exit Sub

    Oh my.. how foolish. Haha thank you

  7. #7
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Quote Originally Posted by ItsMe View Post
    You need to remove your On Error GoTo Err_proc0
    How can I do that?

  8. #8
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Oh forget that, I thought it said "improve" not remove.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by nick404 View Post
    Oh forget that, I thought it said "improve" not remove.
    Yeah, I should have said to comment it out. I was lazy. I add my error trapping as a final step.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Quote Originally Posted by nick404 View Post
    Oh my.. how foolish. Haha thank you
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Unbound text boxes show #ERROR on data entry line
    By GraeagleBill in forum Forms
    Replies: 4
    Last Post: 01-07-2015, 12:44 AM
  2. Replies: 9
    Last Post: 11-05-2014, 09:23 AM
  3. Replies: 3
    Last Post: 12-17-2013, 05:14 AM
  4. Two unbound boxes not updating in table
    By DeathByData in forum Access
    Replies: 29
    Last Post: 05-22-2013, 12:51 PM
  5. Use unbound boxes in a form
    By jjerome512 in forum Forms
    Replies: 2
    Last Post: 01-14-2010, 08:53 PM

Tags for this Thread

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