Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Join Date
    May 2006
    Posts
    30

    Runtime Error 13 Type Mismatch

    All,

    I am getting "Runtime Error 13 Type Mismatch" when the subroutine immediately below executes. frmProducts is the form name and the NewRecordMark sub is shown below. I have tried several ways of passing the form to NewRecordMark and none have worked.

    I am new to Access and have much to learn. I will appreciate any help you can give me on this.

    Thanks,

    Charles
    ---------------------------------------------------------------------
    Private Sub Form_Current()
    NewRecordMark (Forms!frmProducts)
    End Sub
    ---------------------------------------------------------------------
    Sub NewRecordMark(frm As Form)
    Dim intnewrec As Integer

    intnewrec = frm.NewRecord
    If intnewrec = True Then
    MsgBox "You're in a new record." _
    & "@Do you want to add new data?" _
    & "@If not, move to an existing record."
    End If
    End Sub
    ---------------------------------------------------------------------

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,925
    You could try "Variant" instead of "Form" for: Sub NewRecordMark(frm As Variant). <--- changed to variant

    Otherwise "I'm guessing" you could try something like this when calling the function NewRecordMark("SomeStrgingRepresetingWhatsBeingSen t") <-just try it in "".
    Last edited by pkstormy; 01-09-08 at 23:28.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,115
    I suggest you use
    Code:
    Sub NewRecordMark(frm As String)
    
    forms(frm).NewRecord
    George
    Home | Blog

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    The error is being caused by your call to NewRecordMark. NewRecordMark is a Sub and not a Function. A function returns a value and a Sub does not. You are calling NewRecordMark like it is a function and it is trying to return a value, but you are not assigning that value to anything.

    Change the line:
    NewRecordMark (Forms!frmProducts)

    To:
    NewRecordMark Forms!frmProducts

    When you include the () it is interpreted as a function returning a value. A good example is Date() which returns the current date. You can also call a function with () but precede it with the Call reserved word. That will run the function and throw out the returned value.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,115
    Now why the chuffing hell didn't I notice that!

    Good catch DCK
    George
    Home | Blog

  6. #6
    Join Date
    May 2006
    Posts
    30
    Thank you DCK! As georgev said "Good catch..."! I have to learn about Visual Basic's differences from other programming languages I am familiar with. Passing parameters to a procedure without using parentheses is obviously one of those differences.

    This is really a great forum. My question languished for several days on another forum with zero replies. On this forum I quickly got it answered. In the future, I don't think I will bother posting to the other forum.

    Thanks for all of the replies.

    Charles

  7. #7
    Join Date
    May 2009
    Posts
    17
    Quote Originally Posted by DCKunkle
    The error is being caused by your call to NewRecordMark. NewRecordMark is a Sub and not a Function. A function returns a value and a Sub does not. You are calling NewRecordMark like it is a function and it is trying to return a value, but you are not assigning that value to anything.

    Change the line:
    NewRecordMark (Forms!frmProducts)

    To:
    NewRecordMark Forms!frmProducts

    When you include the () it is interpreted as a function returning a value. A good example is Date() which returns the current date. You can also call a function with () but precede it with the Call reserved word. That will run the function and throw out the returned value.
    i also encounter this problem.how to slove it?
    (list of student)form

    Private Sub cmbORDER_Click()
    TxtFilter
    End Sub

    Private Sub cmbSearchby_Click()
    TxtFilter
    End Sub

    Private Sub cmbsortBY_Click()
    TxtFilter
    End Sub

    Private Sub CmdADD_Click()
    Stud_Info_edit.mode = "Add"

    For eX = 0 To 4
    Stud_Info_edit.Data(eX) = ""

    Next eX



    Load Stud_Info_edit
    Stud_Info_edit.Show 1
    End Sub

    Private Sub cmdbold_Click()
    If StudList.Font.Bold = False Then
    StudList.Font.Bold = True
    cnn.Execute "update menucolors set bold='true' where object = 'studlist'"
    cmdbold.FontBold = True
    Else
    StudList.Font.Bold = False
    cnn.Execute "update menucolors set bold='false' where object = 'studlist'"
    cmdbold.FontBold = False


    End If
    End Sub

    Private Sub CmdClose_Click()
    Unload Me
    End Sub

    Private Sub cmdColor_Click()
    On Error GoTo balik
    CD1.ShowColor

    StudList.ForeColor = CD1.Color
    cmdColor.BackColor = CD1.Color
    cnn.Execute "update menucolors set color = '" & CD1.Color & "' where object = 'studList'"




    Exit Sub
    balik:
    check_rsColor
    rsColor.Open "select color from menucolors where object = 'studlist'", cnn
    'MsgBox rsColor(0)
    StudList.ForeColor = rsColor(0)
    cmdColor.BackColor = rsColor(0)

    End Sub

    Private Sub cmdDelete_Click()
    If MsgBox("Do you really want to delete the record of " & StudList.SelectedItem.ListSubItems(1).Text & " " & StudList.SelectedItem.ListSubItems(2).Text & "?", vbYesNo) = vbYes Then
    cnn.Execute "delete from stud_info where stud_num = '" & StudList.SelectedItem.Text & "'"
    rs.Requery 1
    fill_list
    End If
    End Sub

    Private Sub CmdEdit_Click()
    If StudList.ListItems.Count = 0 Then Exit Sub
    Stud_Info_edit.Data(0) = StudList.SelectedItem.Text
    For eX = 1 To 4
    Stud_Info_edit.Data(eX).Text = StudList.SelectedItem.ListSubItems(eX).Text
    Next eX
    Stud_Info_edit.cmbSex = StudList.SelectedItem.ListSubItems(5).Text
    Stud_Info_edit.key = StudList.SelectedItem.Text
    Stud_Info_edit.mode = "edit"
    Load Stud_Info_edit
    Stud_Info_edit.Show 1


    End Sub

    Private Sub Command1_Click()
    If StudList.Font.Italic = False Then
    StudList.Font.Italic = True
    cnn.Execute "update menucolors set italic='true' where object = 'studlist'"
    cmdItalic.FontItalic = True
    Else
    StudList.Font.Italic = False
    cnn.Execute "update menucolors set italic='false' where object = 'studlist'"
    cmdItalic.FontItalic = False


    End If

    End Sub

    Private Sub cmdItalic_Click()
    If StudList.Font.Italic = False Then
    StudList.Font.Italic = True
    cnn.Execute "update menucolors set italic='true' where object = 'studlist'"
    cmdItalic.FontItalic = True
    Else
    StudList.Font.Italic = False
    cnn.Execute "update menucolors set italic='false' where object = 'studlist'"
    cmdItalic.FontItalic = False


    End If

    End Sub

    Private Sub cmdSize_Click()
    cnn.Execute "update menucolors set size = '" & cmdSize.Text & "' where object = 'studlist'"
    StudList.Font.Size = cmdSize.Text
    End Sub

    Private Sub Form_Load()
    Call Connect
    check_rs
    rs.Open "select * from stud_info", cnn
    rsColor.Open "select color,bold,italic,size from menucolors where object = 'studlist'", cnn
    cmdColor.BackColor = rsColor(0)
    'MsgBox rsColor(0)
    StudList.ForeColor = rsColor(0)
    StudList.Font.Bold = rsColor(1)
    StudList.Font.Italic = rsColor(2)
    StudList.Font.Size = rsColor(3)
    cmdbold.FontBold = rsColor(1)
    cmdItalic.FontItalic = rsColor(2)
    cmdSize.Text = rsColor(3)
    fill_list


    End Sub


    Public Sub fill_list()
    StudList.ListItems.Clear
    If rs.RecordCount = 0 Then Exit Sub

    While Not rs.EOF

    Set lst = StudList.ListItems.Add(, , rs(0))
    For eX = 1 To 5
    lst.SubItems(eX) = rs(eX)


    Next eX
    rs.MoveNext

    Wend
    End Sub

    Private Sub Label4_Click()

    End Sub

    Private Sub txtSearch_Change()
    TxtFilter
    End Sub

    Public Sub TxtFilter()
    Dim sby, oby, DASC As String


    If cmbSearchby.ListIndex = -1 Then cmbSearchby.ListIndex = 0
    If cmbsortBY.ListIndex = -1 Then cmbsortBY.ListIndex = 0
    If cmbORDER.ListIndex = -1 Then cmbORDER.ListIndex = 0
    If cmbSearchby.ListIndex = 0 Then
    sby = "stud_num"
    ElseIf cmbSearchby.ListIndex = 1 Then
    sby = "fname"
    ElseIf cmbSearchby.ListIndex = 2 Then
    sby = "ic_num"
    End If

    Select Case cmbsortBY.ListIndex
    Case 0
    oby = "stud_num"
    Case 1
    oby = "fname"
    Case 2
    oby = "ic_num"
    End Select

    Select Case cmbORDER.ListIndex
    Case 0
    DASC = "asc"
    Case 1
    DASC = "desc"
    End Select


    check_rs
    rs.Open "select * from stud_info where " & sby & " like '" & txtSearch & "%' order by " & oby & " " & DASC, cnn



    fill_list









    End Sub
    Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    If KeyAscii = Asc("'") Then KeyAscii = 0

    End Sub

    Student edit (form2)

    Public key, mode As String

    Private Sub cmdCancel_Click()
    Unload Me
    End Sub

    Private Sub CmdSave_Click()
    On Error GoTo RISON
    If Trim(data(0)) = "" Then
    MsgBox "Please enter the student number.", vbInformation + vbCritical, "Missing Data!"
    data(0).SetFocus

    Exit Sub
    ElseIf Trim(data(1)) = "" Then
    MsgBox "Please enter the Full name.", vbInformation + vbCritical, "Missing Data!"
    data(1).SetFocus
    Exit Sub
    ElseIf Trim(cmbSex.Text) = "" Then
    MsgBox "Please enter the sex.", vbInformation + vbCritical, "Missing Data!"
    cmbSex.SetFocus
    Exit Sub
    ElseIf Trim(data(2)) = "" Then
    MsgBox "Please enter the I/C number.", vbInformation + vbCritical, "Missing Data!"
    data(2).SetFocus

    End If


    If UCase(mode) = "EDIT" Then
    cnn.Execute "update stud_info set stud_num = '" & data(0) & "', fname = '" & data(1) & "', ic_num ='" & data(2) & " ',telno = '" & data(3) & "', address = '" & data(4) & "', sex = '" & cmbSex.Text & "'"
    ElseIf UCase(mode) = "ADD" Then

    cnn.Execute "insert into stud_info values('" & data(0) & "','" & data(1) & "','" & data(2) & "','" & data(3) & "','" & data(4) & "','" & cmbSex.Text & "',"

    End If

    rs.Requery 1

    Stud_infoLIST.fill_list

    Unload Me

    Exit Sub
    RISON:
    MsgBox Err.Description
    End Sub

    Private Sub data_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = 13 Then
    SendKeys ("{TAB}")
    End If
    If KeyAscii = Asc("'") Then
    KeyAscii = 0
    End If

    If Index = 0 Or Index = 3 Then

    If KeyAscii >= 48 And KeyAscii <= 57 Then
    ElseIf KeyAscii = 8 Then

    Else
    KeyAscii = 0
    End If

    End If
    End Sub

    modules

    Public cnn As New ADODB.Connection
    Public rs As New ADODB.Recordset
    Public rsColor As New ADODB.Recordset

    Public eX As Integer
    Public lst As ListItem

    Public Sub Connect()

    cnn.CursorLocation = adUseClient
    'cnn.Open "msdasql.1;persist security info = false; data source = student"
    cnn.Open "provider=microsoft.jet.oledb.3.51;persist security info = false; data source = " & App.Path & "\student.mdb;"
    'cnn.Open "provider=Microsoft.jet.oledb.3.51;persist security info= false;data source = " & App.Path & "\student.mdb;"


    End Sub


    Public Sub check_rs()
    If rs.State = 1 Then rs.Close
    End Sub
    Public Sub check_rsColor()
    If rsColor.State = 1 Then rsColor.Close
    End Sub

  8. #8
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I doubt anyone here is going to read through all of code to try to debug the code. You might want to give people a hint of where the problem is. When you get the error, are you prompted to debug it? If so, what line is highlighted.

  9. #9
    Join Date
    May 2009
    Posts
    17
    Quote Originally Posted by DCKunkle
    I doubt anyone here is going to read through all of code to try to debug the code. You might want to give people a hint of where the problem is. When you get the error, are you prompted to debug it? If so, what line is highlighted.
    Sorry.The database is running properly.the problem is occur when i make this database to exe.i click file>make studentdatabase.exe>dekstop.
    When i click this application at dekstop, i getting "Runtime Error 13'' Type Mismatch message box.

  10. #10
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,925
    Make exe? Don't you mean make mde file? You can't make .exe files (and cannot run an *.exe file) from an MSAccess type file. You CAN make an MDE file from an mdb file though.

    If you're trying to make an exe or rename the mdb/mde to exe, it won't work.
    Last edited by pkstormy; 05-23-09 at 04:30.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  11. #11
    Join Date
    May 2009
    Posts
    17
    Quote Originally Posted by pkstormy
    Make exe? Don't you mean make mde file? You can't make .exe files (and cannot run an *.exe file) from an MSAccess type file. You CAN make an MDE file from an mdb file though.

    If you're trying to make an exe or rename the mdb/mde to exe, it won't work.
    thx.so vb6 can't combine with access file into exe file?

  12. #12
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    No, you cannot make an .EXE from an Access database.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  13. #13
    Join Date
    Jun 2009
    Posts
    3
    i am also getting the same error when i run following code. strange is- same code works fine for some worksheets and for some worksheets error msg comes after some lines and when i restart from that cell it works fine. i checked the cell formatting already.

    Sub Macro2()
    '
    ' Macro2 Macro
    ' Macro recorded 6/2/2009 by vharyan
    Dim k
    k = 0
    Do While (k < 1000)

    shubham
    k = k + 1
    Loop

    End Sub
    Sub shubham()
    Dim i
    Dim j
    i = 0
    j = 0
    Do Until (ActiveCell.Offset(j, -2).Value = "")

    i = ActiveCell.Offset(j, -2).Value + i
    j = j + 1
    ActiveCell.Offset(0, 1).Value = i
    Loop

    j = j + 1

    ActiveCell.Offset(j, 0).Range("A1").Select
    Do Until (ActiveCell.Offset(j, -2).Value > 0)

    j = j + 1
    ActiveCell.Offset(j, 0).Range("A1").Select
    If j < 1000 Then Exit Do


    Loop


    End Sub

  14. #14
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Maybe you should use an EXCEL forum for your Excel code?

    You should also learn to indent your code so it's easier to read.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  15. #15
    Join Date
    Mar 2010
    Posts
    3

    Unhappy Similar Error

    I have the same form of error and am new to Visual Basic with Access. I am using Access 2003.
    The following is my code:
    Private Sub Form_Load()
    Dim strDocName As String
    Dim strFilter As String, strName As String

    strName = InputBox("Enter RC", "RC Number")
    strFilter = "RCNumber = " & "'" & strName & "'"

    strDocName = "Spending_Plan_Entry_Tool"
    DoCmd.OpenForm strDocName, strFilter
    End Sub

    The red text is my highlighted error I guess.

    What I have is a form that lists all projects in the database. What I am trying, unsuccessfully I might add, is to create the ability to enter this form and enter the RC Number and Venture Number and have only those RC & Ventures list in the form.

    I know I can do this simply by filter by form but I would rather have the ability to select the department (RC) and Venture and have it pull by those projects in that area.

    Any ideas?

Posting Permissions

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