+ Reply to Thread
Results 1 to 8 of 8

Syntax Error and Compile Error: Expected Line Number or Label...

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Syntax Error and Compile Error: Expected Line Number or Label...

    Hello everyone.

    I am having a strange error. This code block used to work fine. So here is what I did, I changed the part of the code that reads CurrentName from CurrentTM_ID, and that seems to have caused the error. Any suggestions?


    Private Function AddNewCustomer() As String
        Dim Customer As String
        Dim custRS As New ADODB.Recordset
        'allow the user to add New Customers to their PERSONAL customer list
        Customer = InputBox("Create a New Customer", "New Customer")
        If Customer <> "" Then
            If conn <> "" Then
                If conn.State = 1 Then
                    CreateConnection
                End If
            Else
                CreateConnection
               
            End If
            'verify the the newly entered customer does NOT already exist in the database as a customer for this TM before actually adding
    ' This is one of the few places where we will reference TM ID without referencing Sales Org
            If Not FindCustomer(Customer) Then
                conn.Execute "Insert into Customer (CustomerName, TM_ID) Values('" _
                    & Replace(Customer, "'", "''") & "','" & Sheets(VALIDATIONS).Range("CurrentTMID").Value & "')" <--------------------- Error line colored in red
                
                Application.Wait Now + TimeValue("00:00:01")
                LoadCustomers
                AddNewCustomer = Customer
            Else
                MsgBox "You already have a Customer by that Name", vbOKOnly, "Customer exists"
            End If
        End If
    End Function
    Last edited by AnthonyWB; 01-30-2011 at 10:43 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    Does the code know what "CurrentTM_ID" is? as the code does not show "CurrentTM_ID,", it shows
    "CurrentTMID"

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    Dave,

    Thanks, the "corrected" code (I got lost in named ranges)is below. The error however is the same as I had originally posted:

    Private Function AddNewCustomer() As String
        Dim Customer As String
        Dim custRS As New ADODB.Recordset
        'allow the user to add New Customers to their PERSONAL customer list
        Customer = InputBox("Create a New Customer", "New Customer")
        If Customer <> "" Then
            If conn <> "" Then
                If conn.State = 1 Then
                    CreateConnection
                End If
            Else
                CreateConnection
               
            End If
            'verify the the newly entered customer does NOT already exist in the database as a customer for this TM before actually adding
    ' This is one of the few places where we will reference TM ID without referencing Sales Org
            If Not FindCustomer(Customer) Then
                conn.Execute "Insert into Customer (CustomerName, CurrentTMID) Values('" _
                    & Replace(Customer, "'", "''") & "','" & Sheets(VALIDATIONS).Range("CurrentTMID").Value & "')"
                
                Application.Wait Now + TimeValue("00:00:01")
                LoadCustomers
                AddNewCustomer = Customer
            Else
                MsgBox "You already have a Customer by that Name", vbOKOnly, "Customer exists"
            End If
        End If
    End Function

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    Hi,

    With in your code I do not see
    "CurrentName" nor "CurrentTM_ID"
    You do have however, "CurrentTMID"
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    I suppose a sample workbook would be required, with the code and with the error occurring.

  6. #6
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    I found a temporary solution that works, although I am not sure why. I removed the following script form the code:

    Application.Wait Now + TimeValue("00:00:01")

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    What was that part of the code supposed to do?

  8. #8
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Syntax Error and Compile Error: Expected Line Number or Label...

    To be honest I am not sure what it was for. I inherited this project through contractual work, and it's spaghetti code, it's just a mess.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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