dcsimg
Results 1 to 6 of 6
  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    5

    "Method or Data Member Not Found" VBA issues in excel

    Hi there,

    I have no clue what I'm doing but I have copied some code and adjusted to try and fit my purposes but for some reason the first line in my code is causing an issue. I keep getting the error message of "Method or Data Member Not Found" and then when I go to de-bug it is highlighting the first line, which reads:

    Private Sub cmdAdd_Click()

    I am trying to make a form to add the details of a new supplier to a spreadsheet. I have downloaded the practice sheet and opened that up and it's working fine, but for some reason it has an issue with the first line in my sheet.

    I have deleted some .exd files as suggested in another post but this hasn't done anything.

    Microsoft Office 365, Excel Version 1801 (Build 9001.2171)

    I have no idea what VBA version I m running or even how to check - I also have no idea about coding, I just want a form!! Is there a simpler way to make a form to enter into a list of suppliers?? This seems so so long winded...

    Entire Code Text:

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Suppliers")

    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

    'check for a name
    If Trim(Me.txtName.Value) = "" Then
    Me.txtName.SetFocus
    MsgBox "Please enter a supplier name"
    Exit Sub
    End If

    'copy the data to the database
    'use protect and unprotect lines,
    ' with your password
    ' if worksheet is protected
    With ws
    ' .Unprotect Password:="password"
    .Cells(iRow, 1).Value = Me.txtName.Value
    .Cells(iRow, 2).Value = Me.txtWebsite.Value
    .Cells(iRow, 3).Value = Me.txtPhoneNo.Value
    .Cells(iRow, 4).Value = Me.txtAccountNo.Value
    .Cells(iRow, 5).Value = Me.txtEmail.Value
    .Cells(iRow, 6).Value = Me.txtContact.Value
    .Cells(iRow, 7).Value = Me.txtCategory.Value
    .Cells(iRow, 8).Value = Me.txtOpened.Value
    .Cells(iRow, 9).Value = Me.txtUsername.Value
    .Cells(iRow, 10).Value = Me.txtPassword.Value
    ' .Protect Password:="password"
    End With

    'clear the data

    Me.txtName.Value = ""
    Me.txtWebsite.Value = ""
    Me.txtPhoneNo.Value = ""
    Me.txtAccountNo.Value = ""
    Me.txtEmail.Value = ""
    Me.txtContact.Value = ""
    Me.txtCategory.Value = ""
    Me.txtOpened.Value = ""
    Me.txtUsername.Value = ""
    Me.txtPassword.Value = ""
    Me.txtName.SetFocus
    End Sub

  2. #2
    Member pike's Avatar
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    44

    Re: "Method or Data Member Not Found" VBA issues in excel

    Hi BettyCrocker,
    The highlight first line will be yellow to indicates error in routine.
    If you scroll down the actual error line will be highlight too in blue.
    which line is highlighted blue?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,556

    Re: "Method or Data Member Not Found" VBA issues in excel

    Is there a simpler way to make a form to enter into a list of suppliers??
    this is simple, it may be possible to make the code shorter, but it may mean redesigning your form a bit

    "Method or Data Member Not Found"
    is this procedure (sub) actually in the code pane for the userform or in a general module? for the me keyword to be valid, the code would need to be in the form containing the textboxes, else you would need to specify the form by name
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    5

    Re: "Method or Data Member Not Found" VBA issues in excel

    "which line is highlighted blue?[/QUOTE]"

    'check for a name
    If Trim(Me.txtName.Value) = "" Then
    Me.txtName.SetFocus
    MsgBox "Please enter a supplier name"
    Exit Sub
    End If

    ".txtName"

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    5

    Re: "Method or Data Member Not Found" VBA issues in excel

    "is this procedure (sub) actually in the code pane for the userform or in a general module? for the me keyword to be valid, the code would need to be in the form containing the textboxes, else you would need to specify the form by name "

    I have zero clue what you're asking me sorry.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,556

    Re: "Method or Data Member Not Found" VBA issues in excel

    the error indicates there is no object (textbox) with the name txtName in the me object

    Me would refer to a userform, worksheet or other object and for it to be valid the code would have to be in the code module for that object
    possibly replace the ME keyword, with the name of the textboxes container, like userform1.txtname

    or post a sample workbook (zip first) with userform that demonstrates the problem
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.