Results 1 to 8 of 8
  1. #1
    cthai is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Posts
    4

    compile error argument not optional access 2007

    Hi -

    I have a button on a form that will bring up a new for the user to fill out but each time i click on the button it's giving me a compile error: Argument not optional... I dont know why it's costing this error... "AddNewWorksheet_red" is highlighted when i click "OK"




    Code:
    Private Sub txtCARWorksheet_red_Click()
    On Error GoTo EH:
    g_strSource = "txtCarWorksheet_red_Click"
    Dim xrsp As Long
    Dim rs As ADODB.Recordset
    Dim StrSQL As String
    Dim idWorksheet As Long
    Set rs = New ADODB.Recordset
    ' check to see how many wkst exist if none go directly to worksheetform
    '   if many ask if want to create new or review olds
    '   p_CountCAREntries
    Set rs = GetData("p_CountCAREntries_red '" & Me.SSN & "'")
    If rs.EOF = False Then
       If rs!CountEntries > 0 Then
            'goto listing of worksheets
            'ask if they want to go to listing or start new Worksheet
            xrsp = MsgBox("A worksheet already exists for this person." & vbCrLf & " Do you want to create new record?" & vbCrLf & vbCrLf & "Select Yes to create new worksheet." & vbCrLf & "Select No to view existing worksheets.", vbYesNoCancel, "Worksheet already exists")
            Select Case xrsp
                Case 6 'yes create new worksheet
                    idWorksheet = AddNewWorksheet_red(Me.SSN, Me.[Position Title].Value & vbNullString, Me.[SENSITIVITY LEVEL].Value & vbNullString)
                    'DoCmd.OpenForm "frmCaseAdjudicationRecommendation", , , "idCARWorksheet = " & idWorksheet
                    doOpenForm "frmCARWorksheet_red", "idCARWorksheet = " & idWorksheet  'call to function that checks link criteria is in place
                    'DoCmd.Close acForm, "frmFederalEmployeeSuitability", acSaveNo
                    DoCmd.SelectObject acForm, "frmCARWorksheet_red"
                    DoCmd.Maximize
                Case 7 'no view existing worksheets
                    'open list of worksheets
                    doOpenForm "frmCARWorksheetList_red", "SSN = " & Me.SSN   'call to function that checks link criteria is in place
                    DoCmd.SelectObject acForm, "frmCARWorksheetList_red"
                    DoCmd.Maximize
            End Select
       Else
            'go to worksheet form directly
            'Create a new Record for person....
            idWorksheet = AddNewWorksheet_red(Me.SSN, Me.[Position Title].Value & vbNullString, Me.[SENSITIVITY LEVEL].Value & vbNullString)
            doOpenForm "frmCARWorksheet_red", "idCARWorksheet = " & idWorksheet  'call to function that checks link criteria is in place
            DoCmd.SelectObject acForm, "frmCARWorksheet_red"
            DoCmd.Maximize
       End If
    End If
    
    Exit Sub
    EH:
        If g_objErr Is Nothing Then
            InitEH g_objErr
        End If
       g_objErr.HandleError Err, m_FormName, g_strSource
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    How many arguments does that function (AddNewWorksheet_red) require?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cthai is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Posts
    4
    hi pbaldy

    there are 3 argument requires ... when i look at the fucntion that it's pulling from

    Code:
    Public Function AddNewWorksheet_red(ByVal SSN As String, ByVal POSITION As String, ByVal SensitivityLevel As String, ByVal ClearanceLevel As String) As Long
    On Error GoTo EH:
    g_strSource = "AddNewWorksheet_red"
    Dim cmd As ADODB.Command
    Dim strMsg As String
    Dim lngIdWorksheet As Long
     
        Set cmd = New ADODB.Command
        cmd.CommandType = adCmdStoredProc
        cmd.CommandText = "p_CARWorksheetAddNew_red"
        cmd.ActiveConnection = CurrentProject.Connection
     
        With cmd
            .Parameters.Append .CreateParameter("@SSN", adVarChar, adParamInput, 9, SSN)
            .Parameters.Append .CreateParameter("@nvcPosition", adVarChar, adParamInput, 50, POSITION)
            .Parameters.Append .CreateParameter("@nvcPositionSensitivity", adVarChar, adParamInput, 50, SensitivityLevel)
     
        End With
        cmd.Execute , , adExecuteNoRecords
    '    strMsg = "WORKSHEET ID " & cmd.Parameters("@idWorksheet")
    '    MsgBox (strMsg)
    AddNewWorksheet_red = cmd.Parameters("@idWorksheet")
    Exit Function
    EH:
        If g_objErr Is Nothing Then
            InitEH g_objErr
        End If
       g_objErr.HandleError Err, "modMISC", g_strSource
    End Function

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Why do you not compile your code each time you make changes to it? That will make life a lot easier, as you will always see where the compilation errors are.

    As was pointed out above - you are calling AddNewWorksheet_red with three parameters - but you have defined it (Function AddNewWorksheet_red...) with at least 4

    John

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I count 4:

    ByVal SSN As String, ByVal POSITION As String, ByVal SensitivityLevel As String, ByVal ClearanceLevel As String
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Ummm -

    By my count, there are 4 arguments -

    SSN
    Position
    Sensitivitylevel
    Clearancelevel

    John

  7. #7
    cthai is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Posts
    4
    OMG! you guys are great! I was reading the code like a mad man thinking there gotta to be something i am not looking at!... thank you so much...

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    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. Replies: 6
    Last Post: 09-28-2011, 09:20 PM
  2. byref argument type mismatch error
    By karuppasamy in forum Access
    Replies: 1
    Last Post: 06-22-2011, 09:37 AM
  3. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 AM
  4. new compile error!
    By darklite in forum Access
    Replies: 6
    Last Post: 09-02-2010, 05:13 PM
  5. Invalid Argument Error
    By koper in forum Access
    Replies: 2
    Last Post: 06-14-2010, 11:22 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