ExistingTextbox gives "method or data member not found" in Visual Basic 6

Hi,

My VB6 app won't compile anymore.
It tells me my control doesn't exist in the middle of the sub, but doesn't have any problems with it in the beginning of the sub.

me.txtm3 is the troublesome control.

Here's the code:
Private Sub CalPayKgs()
On Error GoTo errorhandler
    If IsNull(Me.txtm3) Or Me.txtm3 = "" Then
        Me.txtm3 = 0
    End If
   
    If IsNull(Me.txtNRLM) Or Me.txtNRLM = "" Then
        Me.txtNRLM = 0
    End If
   
    If IsNull(Me.txtLMKGS) Or Me.txtLMKGS = "" Then
        Me.txtLMKGS = "0"
    End If
   
    If (Me.txtm3 * 333) >= (Me.txtNRLM * Me.txtNRLMKGS) Then ' * * *
        Me.lblPayKgs = Me.txtm3 * 333
    Else
        Me.lblPayKgs = (Me.txtNRLM * Me.txtNRLMKGS)
    End If
   
    If Me.lblPayKgs < Me.txtKG Then
        Me.lblPayKgs = Me.txtKG
    End If
    Exit Sub
errorhandler:
    errore FrmAddress, "CalPayKgs"
End Sub

* * * = .txtm3  is highlighted.

I have tried the following:
Converting the value to a double
Retyping the control name.
Using intellisense to select the control name.
Renaming the control
Deleting the control and readding it.

It's bound to be something really simple, just can't tell what it is.
This code works fine in another part of the app.

Some light for the blind please.
LVL 2
DennisPostAsked:
Who is Participating?
 
peetmCommented:
So the textbox has a value in it does it?

As an aside, you might want to use If Val(Me.txtm3 * 333) i.e., use Val() around controls like this - if things go wrong - like there's text, or nothing in a control like this Val() will at least evaluate to zero.  Of course, if you've error handling you might *not* want this.
0
 
appariCommented:

can you open the .frm file in notepad, copy the code and post it here?
0
 
DennisPostAuthor Commented:
Sure:

VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form FrmAddress
   BackColor       =   &H00EDE8E2&
   Caption         =   "Address cargo details"
   ClientHeight    =   6030
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10575
   BeginProperty Font
      Name            =   "MS Sans Serif"
      Size            =   9.75
      Charset         =   238
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   6030
   ScaleWidth      =   10575
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame3
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   238
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3735
      Left            =   8880
      TabIndex        =   28
      Top             =   2040
      Width           =   1455
      Begin VB.CommandButton cmdPrint
         Caption         =   "Print"
         Height          =   375
         Left            =   120
         TabIndex        =   34
         Top             =   2040
         Width           =   1095
      End
      Begin VB.CommandButton cmdClose
         Caption         =   "Close"
         Height          =   375
         Left            =   120
         TabIndex        =   33
         Top             =   3240
         Width           =   1095
      End
      Begin VB.CommandButton cmdCancel
         Caption         =   "Cancel"
         Height          =   375
         Left            =   120
         TabIndex        =   32
         Top             =   2640
         Width           =   1095
      End
      Begin VB.CommandButton cmdApply
         Caption         =   "Apply"
         Height          =   375
         Left            =   120
         TabIndex        =   31
         Top             =   1440
         Width           =   1095
      End
      Begin VB.CommandButton cmdChange
         Caption         =   "Change"
         Height          =   375
         Left            =   120
         TabIndex        =   30
         Top             =   840
         Width           =   1095
      End
      Begin VB.CommandButton cmdNew
         Caption         =   "New"
         Height          =   375
         Left            =   120
         TabIndex        =   29
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame2
      Caption         =   "Cargo details"
      Height          =   1935
      Left            =   240
      TabIndex        =   6
      Top             =   3840
      Width           =   8415
      Begin VB.TextBox txtm3
         Height          =   375
         Left            =   3960
         TabIndex        =   40
         Top             =   1080
         Width           =   1285
      End
      Begin VB.TextBox txtColli
         Height          =   360
         Left            =   3960
         MaxLength       =   15
         TabIndex        =   12
         ToolTipText     =   "Colli type"
         Top             =   720
         Width           =   1285
      End
      Begin VB.TextBox txtQty
         Height          =   360
         Left            =   1440
         MaxLength       =   9
         TabIndex        =   11
         ToolTipText     =   "The amount of cargo being transported."
         Top             =   720
         Width           =   1285
      End
      Begin VB.TextBox txtComm
         Height          =   360
         Left            =   1440
         MaxLength       =   30
         TabIndex        =   10
         ToolTipText     =   "A brief description of the cargo."
         Top             =   240
         Width           =   6765
      End
      Begin VB.TextBox txtKG
         Height          =   360
         Left            =   1440
         MaxLength       =   9
         TabIndex        =   9
         ToolTipText     =   "Total weight (kgs)"
         Top             =   1080
         Width           =   1285
      End
      Begin VB.TextBox txtNRLM
         Height          =   360
         Left            =   1440
         MaxLength       =   9
         TabIndex        =   8
         ToolTipText     =   "Loading meters"
         Top             =   1440
         Width           =   1285
      End
      Begin VB.TextBox txtLMKGS
         Height          =   285
         Left            =   3960
         MaxLength       =   9
         TabIndex        =   7
         ToolTipText     =   "The weight (kgs) to convert loading meters to payable weight."
         Top             =   1440
         Width           =   1285
      End
      Begin VB.Label lblPayKgs
         BackColor       =   &H80000009&
         BeginProperty Font
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   238
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   6840
         TabIndex        =   27
         Top             =   1440
         Width           =   1455
      End
      Begin VB.Label Label6
         Caption         =   "Payable kgs"
         Height          =   255
         Left            =   5400
         TabIndex        =   20
         Top             =   1440
         Width           =   1215
      End
      Begin VB.Label Label5
         Caption         =   "LM Kgs"
         Height          =   255
         Left            =   3000
         TabIndex        =   19
         Top             =   1440
         Width           =   735
      End
      Begin VB.Label Label4
         Caption         =   "Quantity"
         Height          =   255
         Left            =   120
         TabIndex        =   18
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label3
         Caption         =   "Colli type"
         Height          =   255
         Left            =   3240
         TabIndex        =   17
         Top             =   720
         Width           =   495
      End
      Begin VB.Label Label2
         Caption         =   "Kgs"
         Height          =   255
         Left            =   120
         TabIndex        =   16
         Top             =   1080
         Width           =   375
      End
      Begin VB.Label Label1
         Caption         =   "Cbm"
         Height          =   255
         Left            =   3240
         TabIndex        =   15
         Top             =   1080
         Width           =   495
      End
      Begin VB.Label Label33
         Caption         =   "Commodity"
         Height          =   255
         Left            =   120
         TabIndex        =   14
         Top             =   270
         Width           =   1095
      End
      Begin VB.Label Label28
         Caption         =   "LM"
         Height          =   255
         Left            =   120
         TabIndex        =   13
         Top             =   1440
         Width           =   375
      End
   End
   Begin VB.Frame Frame1
      Caption         =   "Address details"
      Height          =   1695
      Left            =   240
      TabIndex        =   1
      Top             =   2040
      Width           =   8415
      Begin VB.TextBox txtTime
         Height          =   375
         Left            =   6960
         MaxLength       =   13
         TabIndex        =   23
         Top             =   1200
         Width           =   1215
      End
      Begin VB.TextBox txtDate
         Height          =   375
         Left            =   4920
         MaxLength       =   8
         TabIndex        =   22
         Top             =   1200
         Width           =   1215
      End
      Begin VB.TextBox txtReference
         Height          =   375
         Left            =   1440
         MaxLength       =   50
         TabIndex        =   21
         Top             =   720
         Width           =   6735
      End
      Begin VB.ComboBox cboPlace
         Height          =   360
         Left            =   1440
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   1200
         Width           =   2655
      End
      Begin VB.TextBox txtAddress
         Height          =   375
         Left            =   1440
         TabIndex        =   2
         Top             =   240
         Width           =   6735
      End
      Begin VB.Label lblAdresID
         Caption         =   "0"
         Height          =   375
         Left            =   960
         TabIndex        =   36
         Top             =   240
         Width           =   375
      End
      Begin VB.Label lblPlaceID
         Caption         =   "0"
         Height          =   255
         Left            =   840
         TabIndex        =   35
         Top             =   1320
         Width           =   375
      End
      Begin VB.Label Label12
         Caption         =   "Date"
         Height          =   255
         Left            =   4200
         TabIndex        =   26
         Top             =   1200
         Width           =   615
      End
      Begin VB.Label Label11
         Caption         =   "Time"
         Height          =   255
         Left            =   6240
         TabIndex        =   25
         Top             =   1200
         Width           =   495
      End
      Begin VB.Label Label10
         Caption         =   "Reference"
         Height          =   255
         Left            =   120
         TabIndex        =   24
         Top             =   720
         Width           =   975
      End
      Begin VB.Label Label8
         Caption         =   "Address"
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label7
         Caption         =   "Place"
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   1200
         Width           =   615
      End
   End
   Begin MSFlexGridLib.MSFlexGrid flxAddress
      Height          =   1575
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   10095
      _ExtentX        =   17806
      _ExtentY        =   2778
      _Version        =   393216
      AllowUserResizing=   1
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   238
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.Label lblPreNr
      Caption         =   "0"
      Height          =   255
      Left            =   1440
      TabIndex        =   39
      Top             =   0
      Width           =   375
   End
   Begin VB.Label lblOrderNr
      Caption         =   "0"
      Height          =   255
      Left            =   2280
      TabIndex        =   38
      Top             =   1800
      Width           =   495
   End
   Begin VB.Label lblAddressID
      Caption         =   "0"
      Height          =   255
      Left            =   0
      TabIndex        =   37
      Top             =   0
      Width           =   375
   End
End
Attribute VB_Name = "FrmAddress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim strPrevFrm As String
Dim LocAction As String

Private Sub cmdApply_Click()
   
    If glPreAdresNr = 0 Then
        glPreAdresNr = GetNextPreNR
    End If
    If LocAction = "New" Then
        If InsertAddress Then
            LoadFlex
        End If
    ElseIf LocAction = "Change" Then
        UpdateAddress
    End If
   
    Me.cmdApply.Enabled = False
    Me.cmdCancel.Enabled = False
    Me.cmdChange.Enabled = True
    Me.cmdClose.Enabled = True
    Me.cmdNew.Enabled = True
    Me.cmdPrint.Enabled = True
End Sub

Private Sub cmdCancel_Click()
    Disable FrmAddress
    Me.cmdApply.Enabled = False
    Me.cmdCancel.Enabled = False
    Me.cmdClose.Enabled = True
    Me.cmdNew.Enabled = True
   
    If Me.lblAddressID > 0 Then
        Me.cmdChange.Enabled = True
        Me.cmdPrint.Enabled = True
    End If
   
End Sub

Private Sub cmdClose_Click()
    gsPrevFrm = strPrevFrm
    If gsPrevFrm = "frmFTL" Then
        frmFTL.Show
    End If
    Unload Me
End Sub

Private Sub cmdChange_Click()
    LocAction = "Change"
    Me.cmdApply.Enabled = True
    Me.cmdCancel.Enabled = True
    Me.cmdChange.Enabled = False
    Me.cmdClose.Enabled = False
    Me.cmdNew.Enabled = False
    Me.cmdPrint.Enabled = False
End Sub

Private Sub cmdNew_Click()
    LocAction = "New"
    Clear
    Me.cmdApply.Enabled = True
    Me.cmdCancel.Enabled = True
    Me.cmdChange.Enabled = False
    Me.cmdClose.Enabled = False
    Me.cmdNew.Enabled = False
    Me.cmdPrint.Enabled = False
End Sub

Private Sub flxAddress_Click()
   
    With Me.flxAddress
        .Col = 0
        Me.lblAddressID = .Text
    End With
   
    Me.cmdApply.Enabled = False
    Me.cmdCancel.Enabled = False
    Me.cmdClose.Enabled = True
    Me.cmdNew.Enabled = True
   
    If Me.lblAddressID > 0 Then
        Me.cmdChange.Enabled = True
        Me.cmdPrint.Enabled = True
    End If
End Sub

Private Sub Form_Activate()
    Screen.MousePointer = vbDefault
    If gsPrevFrm = "SelCust" Then
        If glAddressID > 0 Then
            Me.lblPlaceID = GetPlaceID(glAddressID)
        End If
    End If
    Me.Enabled = True
End Sub

Private Sub Form_Load()

    strPrevFrm = gsPrevFrm
    If glDossierNR > 0 And glPreAdresNr > 0 Then
        LoadFlex
    End If
End Sub

Private Sub DoFlxAddress()

With Me.flxAddress

    .Col = 0    'ID
    .Col = 1    'FileNr
    .Col = 2    'DossierNr
    .Col = 3    'Type
    .Col = 4    'OrderNr
    .Col = 5    'AddressID
    .Col = 6    'Ref
    .Col = 7    'PlaceID
    .Col = 8    'Date
    .Col = 9    'Time(s)
    .Col = 10   'Goods
    .Col = 11   'Qty
    .Col = 12   'ColliType
    .Col = 13   'Kgs
    .Col = 14   'Cbm
    .Col = 15   'LM
    .Col = 16   'LMKgs
    .Col = 17   'PayKgs

End With

End Sub

Private Sub txtAddress_DblClick()
    SelAddress
End Sub

Private Sub txtAddress_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then SelAddress
End Sub

Private Sub txtDate_KeyPress(KeyAscii As Integer)
    DateField Me.txtDate, KeyAscii
End Sub

Private Sub txtDate_LostFocus()
    If IsDate(Me.txtDate) = False Then Me.txtDate = ""
End Sub

Private Sub txtKG_KeyPress(KeyAscii As Integer)
    Comma Me.txtKG, KeyAscii
End Sub

Private Sub txtLMKgs_KeyPress(KeyAscii As Integer)
    Comma Me.txtLMKGS, KeyAscii
End Sub

Private Sub txtLMKgs_LostFocus()
    CalPayKgs
End Sub

Private Sub txtM3_KeyPress(KeyAscii As Integer)
    Comma Me.txtm3, KeyAscii
End Sub

Private Sub txtM3_LostFocus()
    CalPayKgs
End Sub

Private Sub txtNRLM_KeyPress(KeyAscii As Integer)
    Comma Me.txtNRLM, KeyAscii
End Sub

Private Sub txtNRLM_LostFocus()
    CalPayKgs
End Sub

Private Sub txtQty_KeyPress(KeyAscii As Integer)
    Comma Me.txtQty, KeyAscii
    If KeyAscii = 43 Or KeyAscii = 44 Then KeyAscii = 0
End Sub
Private Sub SelAddress()
On Error GoTo errorhandler
    Screen.MousePointer = vbHourglass
    Me.txtAddress = ""
    gsInstant = "Customer"
    gsPrevFrm = "frmAddress"
    Tbl = "tblCust"
    Me.Enabled = False
    frmSelCust.Caption = "Form Addresses field Address"
    frmSelCust.lblDynamic.Caption = "Please select an address here"
    frmSelCust.Show
    frmSelCust.txtSearchValue.SetFocus
    Exit Sub
errorhandler:
    errore FrmAddress, "SelAddress"
End Sub
Private Sub Clear()
Dim Ctl As Control

    For Each Ctl In Me.Controls
        If TypeOf Ctl Is TextBox Then
            Ctl = ""
        End If
    Next
   
    Me.lblPayKgs = ""
    Me.lblAdresID = 0
    Me.lblPlaceID = 0
    Me.lblAddressID = 0

    Me.cboPlace.Clear
End Sub
Private Sub LoadFlex()
    SQLQuery = "SELECT A.ID, PreNr, A.AddressID, C.Naam, A.PlaceID, P.Place FROM tblAddresses A, " & _
                "tblCust C, Places P WHERE C.AdresID = A.AddressID AND P.PlaceID = A.PlaceID " & _
                "AND DossierNr = " & glDossierNR & " AND Type = sqlquote(" & gsAddressType & ")"
   
    If OpenADOrs(False, "C") = True Then
        If FillFlx(Me.flxAddress, rsADO, True) = True Then
            DoFlxAddress
        End If
    End If
End Sub

Private Function InsertAddress() As Boolean
On Error GoTo errorhandler
    If glDossierNR > 0 Then
        SQLExec = "INSERT INTO Address(FileNr, DossierNr, Type, OrderNr, AddressID, Ref, " & _
                  "PlaceID, [Date], [Time], Goods, Qty, ColliType, Kgs, Cbm, LM, LMKgs, " & _
                  "PayKgs, Creator, CreateDate, Amendor, AmendDate) " & _
                  "VALUES(" & glAddressID & "," & glFileNR & ", " & glDossierNR & ", " & SQLQuote(gsAddressType) & ", " & _
                  "" & SQLQuote(Trim(Me.txtReference)) & ", " & Me.lblPlaceID & ", " & _
                  "" & SQLDate(Me.txtDate) & ", " & SQLQuote(Trim(Me.txtTime)) & ", " & _
                  "" & SQLQuote(Trim(Me.txtComm)) & ", " & Me.txtQty & ", " & SQLQuote(Trim(Me.txtColli)) & ", " & _
                  "" & SQLNum(Me.txtKG) & ", " & SQLNum(Me.txtm3) & ", " & SQLNum(Me.txtNRLM) & ", " & _
                  "" & SQLNum(Me.txtLMKGS) & ", " & SQLNum(Me.lblPayKgs) & ", " & _
                  "" & glUserID & ", " & SQLNow(Date) & ", " & glUserID & ", " & SQLNow(Date) & ");"
    Else
        SQLExec = "INSERT INTO Address(PreNr, Type, OrderNr, AddressID, Ref, " & _
                  "PlaceID, [Date], [Time], Goods, Qty, ColliType, Kgs, Cbm, LM, LMKgs, " & _
                  "PayKgs, Creator, CreateDate, Amendor, AmendDate) " & _
                  "VALUES(" & glPreAdresNr & ", " & SQLQuote(gsAddressType) & ", " & _
                  "" & SQLQuote(Trim(Me.txtReference)) & ", " & Me.lblPlaceID & ", " & _
                  "" & SQLDate(Me.txtDate) & ", " & SQLQuote(Trim(Me.txtTime)) & ", " & _
                  "" & SQLQuote(Trim(Me.txtComm)) & ", " & Me.txtQty & ", " & SQLQuote(Trim(Me.txtColli)) & ", " & _
                  "" & SQLNum(Me.txtKG) & ", " & SQLNum(Me.txtm3) & ", " & SQLNum(Me.txtNRLM) & ", " & _
                  "" & SQLNum(Me.txtLMKGS) & ", " & SQLNum(Me.lblPayKgs) & ", " & _
                  "" & glUserID & ", " & SQLNow(Date) & ", " & glUserID & ", " & SQLNow(Date) & ");"
    End If
    If OpenADOcnn Then
        AdoConn.Execute SQLExec
        InsertAddress = True
        AdoConn.Close
        Set AdoConn = Nothing
    End If
    Exit Function
errorhandler:
    InsertAddress = False
    errore FrmAddress, "InsertAddress"
End Function

Private Sub UpdateAddress()
On Error GoTo errorhandler



Exit Sub
errorhandler:
    errore FrmAddress, "UpdateAddress"
End Sub
Private Sub CalPayKgs()
On Error GoTo errorhandler
    If IsNull(Me.txtm3) Or Me.txtm3 = "" Then
        Me.txtm3 = 0
    End If
   
    If IsNull(Me.txtNRLM) Or Me.txtNRLM = "" Then
        Me.txtNRLM = 0
    End If
   
    If IsNull(Me.txtLMKGS) Or Me.txtLMKGS = "" Then
        Me.txtLMKGS = "0"
    End If
   
    If (Me.txtm3 * 333) >= (Me.txtNRLM * Me.txtNRLMKGS) Then
        Me.lblPayKgs = Me.txtm3 * 333
    Else
        Me.lblPayKgs = (Me.txtNRLM * Me.txtNRLMKGS)
    End If
   
    If Me.lblPayKgs < Me.txtKG Then
        Me.lblPayKgs = Me.txtKG
    End If
    Exit Sub
errorhandler:
    errore FrmAddress, "CalPayKgs"
End Sub

Private Function GetPlaceID(ByVal AdresID As Long) As Long
On Error GoTo errorhandler

    SQLQuery = "SELECT Place FROM Places WHERE Place LIKE '%"

Exit Function
errorhandler:
    errore FrmAddress, "GetPlaceID"
End Function
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DennisPostAuthor Commented:
cough, cough.....

VB can put you of track sometimes.
The control that was highlighted was not the problem.
The problem control is on the same line though. Me.txtNRLMKGS should be Me.txtLMKGS

That VAL tip is a good one thanks.
0
 
peetmCommented:
LOL - well, glad you got it sorted!
0
 
appariCommented:
the problem is no control with name txtNRLMKGS is existing on the form.

If (Me.txtm3 * 333) >= (Me.txtNRLM * Me.txtNRLMKGS) Then
0
 
DennisPostAuthor Commented:
Professor,
You didn't really answer the question.
Just gave me better code to reveal the actual problem.

Your points are very modest, considering your profie.... ?!?!?
No time I guess....

Good luck with the patents!
0
 
DennisPostAuthor Commented:
Sorry Appari,
You were seconds too late.
You also should have gotten a slice of the cake.

Here's 1000 imaginary points and my thanks.
0
 
peetmCommented:
>> DennisPost

>>Professor,

Nope, I'm not a Prof - and don't ever expect to be one - too much competition, and far too much paper-work!

Points:  only just started playing with EE really - too much proper work to do, but it's sometimes a nice distraction.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.