+ Reply to Thread
Results 1 to 4 of 4

Variable not found & Runtime error 13

Hybrid View

DJvdW Variable not found & Runtime... 09-07-2013, 04:10 PM
TMS Re: Variable not found &... 09-07-2013, 04:32 PM
DJvdW Re: Variable not found &... 09-08-2013, 06:51 AM
TMS Re: Variable not found &... 09-08-2013, 08:17 AM
  1. #1
    Registered User
    Join Date
    09-06-2012
    Location
    Alberton, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    30

    Variable not found & Runtime error 13

    I am creating a UserForm for users to complete to create a new account. I have the following boxes in my form:

    AccTypeCodeComboBox
    AccTypeDescrTextBox
    AccNumberTextBox
    AccDescrTextBox

    The code below runs on exiting the AccNumberTextBox.

    The line "ChkType = AccTypeDescrComboBox.Value" results in a Compile Error: Variable not found - "AccTypeDescrComboBox" is highlighted.

    The line "ChkNr = AccNumberTextBox.Value" results in a Run-time error 13: Type mismatch - "AccNumberTextBox" is highlighted.

    The runtime error only occurred after I added the section starting at "If IsNull(Me.AccNumberTextBox.Value) Then". Before that there were no runtime error.

    I need help with:

    1) As what must I define the variable "AccTypeDescrComboBox"?

    2) How do I check that "AccNumberTextBox is not empty?

    I would appreciate any suggestions you may have.


    Option Explicit
    
    Private Sub AccNumberTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
    Dim ChkType As String
    Dim ChkNr As Long
    Dim Ulimit As Long
    Dim Llimit As Long
    Dim i As Integer
    Dim lRow As Long
    
    ChkType = AccTypeDescrComboBox.Value
    ChkNr = AccNumberTextBox.Value
    Ulimit = Application.WorksheetFunction.VLookup(AccTypeCodeComboBox.Value, Sheets("Lists").Range("A7:D19"), 4, False)
    Llimit = Application.WorksheetFunction.VLookup(AccTypeCodeComboBox.Value, Sheets("Lists").Range("A7:D19"), 3, False)
    
    If IsNull(Me.AccNumberTextBox.Value) Then
      MsgBox ("You must enter a Number in this field")
      AccNumberTextBox.SetFocus
      Exit Sub
    End If
    
    If Not IsNumeric(AccNumberTextBox.Value) Then
      MsgBox ("You must enter a Number in this field")
      AccNumberTextBox.SetFocus
      Exit Sub
    End If
    
    If ChkNr < Llimit Or ChkNr > Ulimit Then
      MsgBox ("You have entered an Account Number that is not in the allowable range for the Type of Account you have selected. For an Account Type of " & ChkType & ", you must enter an Account number between " & Llimit & " and " & Ulimit & ". Please enter a new Account Number.")
      AccNumberTextBox.Value = ""
      AccNumberTextBox.SetFocus
      Exit Sub
    End If
    
    Range("B12").Select
    lRow = ActiveCell.CurrentRegion.Rows.Count + 11
    For i = 12 To lRow
      If ChkNr = Range("D" & i).Value Then
        MsgBox ("You have entered an Account Number which already exists!")
        AccNumberTextBox.SetFocus
        Exit Sub
      End If
    Next i
    
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,135

    Re: Variable not found & Runtime error 13

    There seems to be some inconsistency in the way you refer to this object: AccTypeDescrTextBox.

    Is it a text box or a combo box?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-06-2012
    Location
    Alberton, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Variable not found & Runtime error 13

    Thanks TMS

    I have corrected AccTypeDescrComboBox to AccTypeDescrTextBox. This has resolved the 'Variable not found' error.

    Now I only need to resolve the Runtime error.

    Regards
    Deon

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,135

    Re: Variable not found & Runtime error 13

    I would suggest you post a sample workbook.


    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Runtime error '53': File not found
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-03-2015, 02:36 PM
  2. Runtime error: File could not be found...even though I just opened it
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2013, 03:41 PM
  3. Replies: 1
    Last Post: 11-17-2012, 11:10 PM
  4. Runtime error 91 Objecr Variable of With block variable not set
    By s_ali_hassan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2010, 05:28 AM
  5. Replies: 8
    Last Post: 02-17-2009, 02:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1