Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2011
    Posts
    57

    Unanswered: Argument not pptional

    I am trying to add a recordset to a table in access, but it's giving me an "Argument not optional" error. I counted and I have all arguments in there. My code is below. The bolded words are what it's highlighting... Could anyone please help me?

    Code:
    Private Sub cmd_add_Click()
    On Error GoTo Err_cmd_add_Click
    
    Dim dbs As Database
    Dim rst As Recordset
    Dim strassy As String
    Dim strname As String
    Dim strframe As Long
    Dim strtrim As Double
    Dim strrotation As String
    Dim strmaterial As String
    Dim strheat As String
    Dim strmfg As String
    Dim strscalefactor As String
    Dim strbumps As String
    Dim strscallops As String
    Dim strlabys As String
    Dim strtape As String
    Dim strfinal As String
    Dim strweld As String
    Dim strcssemi As String
    Dim strdssemi As String
    Dim strcsforg As String
    Dim strdsforg As String
    Dim strgold As String
    Dim strauthor As String
    
    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset("AttributesTbl", dbOpenDynaset)
    
    If IsNull(Me.tbo_assembly) Then
        MsgBox "You must enter in an assembly part number"
        Exit Sub
    Else
        strassy = Me.tbo_assembly
    End If
    
    If IsNull(Me.cbo_name) Then
        MsgBox "You must enter in an impeller name"
        Exit Sub
    Else
        strname = Me.cbo_name
    End If
    
    If IsNull(Me.cbo_frame) Then
        MsgBox "You must enter in a frame size"
        Exit Sub
    Else
        strframe = Me.cbo_frame
    End If
    
    If IsNull(Me.cbo_trim) Then
        MsgBox "You must enter in a trim"
        Exit Sub
    Else
        strtrim = Me.cbo_trim
    End If
    
    If IsNull(Me.cbo_rotation) Then
        MsgBox "You must enter in a rotation"
        Exit Sub
    Else
        strrotation = Me.cbo_rotation
    End If
    
    If IsNull(Me.cbo_material) Then
        MsgBox "You must enter in a material specification"
        Exit Sub
    Else
        strmaterial = Me.cbo_material
    End If
    
    If IsNull(Me.cbo_heat) Then
        MsgBox "You must enter in a heat specification"
        Exit Sub
    Else
        strheat = Me.cbo_heat
    End If
    
    If IsNull(Me.cbo_mfg) Then
        MsgBox "You must enter in a manufacturing method"
        Exit Sub
    Else
        strmfg = Me.cbo_mfg
    End If
    
    If IsNull(Me.cbo_scale) Then
        MsgBox "You must enter in a manufacturing method"
        Exit Sub
    Else
        strscalefactor = Me.cbo_scale
    End If
    
    
    If IsNull(Me.cbo_bumps) Then
        MsgBox "You must enter in a % of bumps"
        Exit Sub
    Else
        strbumps = Me.cbo_bumps
    End If
    
    If IsNull(Me.chk_scallops) Then
        strscallops = False
    Else
        strscallops = Me.chk_scallops
    End If
    
    If IsNull(Me.chk_teeth) Then
        strlabys = False
    Else
        strlabys = Me.chk_teeth
    End If
    
    If IsNull(Me.cbo_tp1) Then
        strtape = ""
    Else
        strtape = Me.cbo_tp1
    End If
    
    If IsNull(Me.tbo_final) Then
        strfinal = "n/a"
    Else
        strfinal = Me.tbo_final
    End If
    
    If IsNull(Me.tbo_weldment) Then
       strweld = "n/a"
        Exit Sub
    Else
        strweld = Me.tbo_weldment
    End If
    
    If IsNull(Me.tbo_coversemi) Then
        MsgBox "Please enter in the cover semi machining part number"
        Exit Sub
    Else
        strcssemi = Me.tbo_coversemi
    End If
    
    If IsNull(Me.tbo_discsemi) Then
        MsgBox "Please enter in the disc semi machining part number"
        Exit Sub
    Else
        strdssemi = Me.tbo_discsemi
    End If
    
    If IsNull(Me.tbo_coverforging) Then
        MsgBox "Please enter in the cover forging part number"
        Exit Sub
    Else
        strcsforg = Me.tbo_coverforging
    End If
    
    If IsNull(Me.tbo_discforging) Then
        strdsforg = "n/a"
    Else
        strdsforg = Me.tbo_discforging
    End If
    
    If IsNull(Me.tbo_gold) Then
        strgold = "n/a"
    Else
        strgold = Me.tbo_gold
    End If
    
    If IsNull(Me.cbo_author) Then
        strauthor = "n/a"
    Else
        strauthor = Me.cbo_author
    End If
    
    If MsgBox("Do You Want To Save This Record?", vbQuestion + vbYesNo, "Save Record?") = vbNo Then
        Me.Undo
        MsgBox "Impeller has not been added to database", vbInformation, "Save Cancelled"
        
     Else
        Debug.Print DCount("Assembly", "AttributesTbl", "Assembly ='" & Me.tbo_assembly & "'")
        If DCount("Assembly", "AttributesTbl", "Assembly ='" & Me.tbo_assembly & "'") <> 0 Then
            MsgBox "This assembly part number already exists in the database."
            Me.Undo
            Exit Sub
        End If
    
    End If
    
    
    AddRecord rst, strassy, strname, strframe, strtrim, strrotation, strmaterial, _
        strheat, strmfg, strbumps, strscallops, strlabys, strtape, strfinal, _
        strweld, strcssemi, strdssemi, strcsforg, strdsforg, strgold, strauthor
    
    rst.Close
    dbs.Close
    
    Exit_cmd_add_Click:
        Exit Sub
    
    Err_cmd_add_Click:
        MsgBox Err.Description
        Resume Exit_cmd_add_Click
        
    End Sub
    
    
    Function AddRecord(rstTemp As Recordset, strassy As String, strname As String, strframe As Long, _
        strtrim As Double, strrotation As String, strmaterial As String, strheat As String, _
        strmfg As String, strscalefactor As String, strbumps As String, strscallops As String, strlabys As String, _
        strtape As String, strfinal As String, strweld As String, strcssemi As String, strdssemi As String, _
        strcsforg As String, strdsforg As String, strgold As String, strauthor As String)
     With rstTemp
     .AddNew
     !Assembly = strassy
     !ImpellerName = strname
     !FrameSize = strframe
     !Trim = strtrim
     !Rotation = strrotation
     !Material = strmaterial
     !HeatTreat = strheat
     !MfgMethod = strmfg
     !Scallops = strscallops
     !ScaleFactor = strscalefactor
     !Bumps = strbumps
     !RotatingTeeth = strlabys
     !tp1Name = strtape
     !Final = strfinal
     !Weldment = strweld
     !CoverSemiMach = strcssemi
     !DiscSemiMach = strdssemi
     !CoverForging = strcsforg
     !DiscForging = strdsforg
     !Gold = strgold
     !AddedBy = strauthor
     .Update
     .Bookmark = .LastModified
     
     End With
     
     
        End Function
    Last edited by nic311; 07-30-12 at 16:15.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I don't see anything in bold, but you might try disambiguating these:

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Paul

  3. #3
    Join Date
    Nov 2011
    Posts
    57
    It's highlighting the AddRecord - when I call the function in the original procedure...


    AddRecord rst, strassy, strname, strframe, strtrim, strrotation, strmaterial, _
    strheat, strmfg, strbumps, strscallops, strlabys, strtape, strfinal, _
    strweld, strcssemi, strdssemi, strcsforg, strdsforg, strgold, strauthor

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I count 22 arguments and 21 being passed. Am I blind?
    Paul

  5. #5
    Join Date
    Nov 2011
    Posts
    57
    Ok you're right, I had missed one... but in the actual function, so I had more all the arguments in the function that I had above, but one extra above. I added it and I'm still receiving the same error...

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    What does the code look like now?
    Paul

  7. #7
    Join Date
    Nov 2011
    Posts
    57
    Code:
    Private Sub cmd_add_Click()
    On Error GoTo Err_cmd_add_Click
    
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strassy As String
    Dim strname As String
    Dim strframe As Long
    Dim strtrim As Double
    Dim strrotation As String
    Dim strmaterial As String
    Dim strheat As String
    Dim strmfg As String
    Dim strscalefactor As String
    Dim strbumps As String
    Dim strscallops As String
    Dim strlabys As String
    Dim strtape As String
    Dim strfinal As String
    Dim strweld As String
    Dim strcssemi As String
    Dim strdssemi As String
    Dim strcsforg As String
    Dim strdsforg As String
    Dim strgold As String
    Dim strauthor As String
    
    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset("AttributesTbl", dbOpenDynaset)
    
    If IsNull(Me.tbo_assembly) Then
        MsgBox "You must enter in an assembly part number"
        Exit Sub
    Else
        strassy = Me.tbo_assembly
    End If
    
    If IsNull(Me.cbo_name) Then
        MsgBox "You must enter in an impeller name"
        Exit Sub
    Else
        strname = Me.cbo_name
    End If
    
    If IsNull(Me.cbo_frame) Then
        MsgBox "You must enter in a frame size"
        Exit Sub
    Else
        strframe = Me.cbo_frame
    End If
    
    If IsNull(Me.cbo_trim) Then
        MsgBox "You must enter in a trim"
        Exit Sub
    Else
        strtrim = Me.cbo_trim
    End If
    
    If IsNull(Me.cbo_rotation) Then
        MsgBox "You must enter in a rotation"
        Exit Sub
    Else
        strrotation = Me.cbo_rotation
    End If
    
    If IsNull(Me.cbo_material) Then
        MsgBox "You must enter in a material specification"
        Exit Sub
    Else
        strmaterial = Me.cbo_material
    End If
    
    If IsNull(Me.cbo_heat) Then
        MsgBox "You must enter in a heat specification"
        Exit Sub
    Else
        strheat = Me.cbo_heat
    End If
    
    If IsNull(Me.cbo_mfg) Then
        MsgBox "You must enter in a manufacturing method"
        Exit Sub
    Else
        strmfg = Me.cbo_mfg
    End If
    
    If IsNull(Me.cbo_scale) Then
        MsgBox "You must enter in a scale factor"
        Exit Sub
    Else
        strscalefactor = Me.cbo_scale
    End If
    
    
    If IsNull(Me.cbo_bumps) Then
        MsgBox "You must enter in a % of bumps"
        Exit Sub
    Else
        strbumps = Me.cbo_bumps
    End If
    
    If IsNull(Me.chk_scallops) Then
        strscallops = False
    Else
        strscallops = Me.chk_scallops
    End If
    
    If IsNull(Me.chk_teeth) Then
        strlabys = False
    Else
        strlabys = Me.chk_teeth
    End If
    
    If IsNull(Me.cbo_tp1) Then
        strtape = ""
    Else
        strtape = Me.cbo_tp1
    End If
    
    If IsNull(Me.tbo_final) Then
        strfinal = "n/a"
    Else
        strfinal = Me.tbo_final
    End If
    
    If IsNull(Me.tbo_weldment) Then
       strweld = "n/a"
        Exit Sub
    Else
        strweld = Me.tbo_weldment
    End If
    
    If IsNull(Me.tbo_coversemi) Then
        MsgBox "Please enter in the cover semi machining part number"
        Exit Sub
    Else
        strcssemi = Me.tbo_coversemi
    End If
    
    If IsNull(Me.tbo_discsemi) Then
        MsgBox "Please enter in the disc semi machining part number"
        Exit Sub
    Else
        strdssemi = Me.tbo_discsemi
    End If
    
    If IsNull(Me.tbo_coverforging) Then
        MsgBox "Please enter in the cover forging part number"
        Exit Sub
    Else
        strcsforg = Me.tbo_coverforging
    End If
    
    If IsNull(Me.tbo_discforging) Then
        strdsforg = "n/a"
    Else
        strdsforg = Me.tbo_discforging
    End If
    
    If IsNull(Me.tbo_gold) Then
        strgold = "n/a"
    Else
        strgold = Me.tbo_gold
    End If
    
    If IsNull(Me.cbo_author) Then
        strauthor = "n/a"
    Else
        strauthor = Me.cbo_author
    End If
    
    If MsgBox("Do You Want To Save This Record?", vbQuestion + vbYesNo, "Save Record?") = vbNo Then
        Me.Undo
        MsgBox "Impeller has not been added to database", vbInformation, "Save Cancelled"
        
     Else
        Debug.Print DCount("Assembly", "AttributesTbl", "Assembly ='" & Me.tbo_assembly & "'")
        If DCount("Assembly", "AttributesTbl", "Assembly ='" & Me.tbo_assembly & "'") <> 0 Then
            MsgBox "This assembly part number already exists in the database."
            Me.Undo
            Exit Sub
        End If
    
    End If
    
    
    AddRecord rst, strassy, strname, strframe, strtrim, strrotation, strmaterial, _
        strheat, strmfg, strbumps, strscallops, strlabys, strtape, strfinal, _
        strweld, strcssemi, strdssemi, strcsforg, strdsforg, strgold, strauthor, strscalefactor
    
    rst.Close
    dbs.Close
    
    Exit_cmd_add_Click:
        Exit Sub
    
    Err_cmd_add_Click:
        MsgBox Err.Description
        Resume Exit_cmd_add_Click
        
    End Sub
    
    
    Function AddRecord(rstTemp As Recordset, strassy As String, strname As String, strframe As Long, _
        strtrim As Double, strrotation As String, strmaterial As String, strheat As String, _
        strmfg As String, strscalefactor As String, strbumps As String, strscallops As String, strlabys As String, _
        strtape As String, strfinal As String, strweld As String, strcssemi As String, strdssemi As String, _
        strcsforg As String, strdsforg As String, strgold As String, strauthor As String, strscalefactor As String)
     With rstTemp
     .AddNew
     !Assembly = strassy
     !ImpellerName = strname
     !FrameSize = strframe
     !Trim = strtrim
     !Rotation = strrotation
     !Material = strmaterial
     !HeatTreat = strheat
     !MfgMethod = strmfg
     !Scallops = strscallops
     !ScaleFactor = strscalefactor
     !Bumps = strbumps
     !RotatingTeeth = strlabys
     !tp1Name = strtape
     !Final = strfinal
     !Weldment = strweld
     !CoverSemiMach = strcssemi
     !DiscSemiMach = strdssemi
     !CoverForging = strcsforg
     !DiscForging = strdsforg
     !Gold = strgold
     !AddedBy = strauthor
     .Update
     .Bookmark = .LastModified
     
     End With
     
     
    End Function
    The last one is the one I added

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Now it's 22 and 23 (are you counting?). The last one you added to the function is already in the middle of it. I'm surprised you don't get a compile error.
    Paul

Posting Permissions

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