+ Reply to Thread
Results 1 to 10 of 10

Invalid Qualifier

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Invalid Qualifier

    My code:
    Private Sub SubmitButton_Click()
        Dim LastName As String, FirstName As String, DrugName As String
        Dim DateRec As Date
        Dim FullName As String
        Dim DrugCode As Integer, Unit As Integer
        Dim Amount As Double, Price As Double
        Dim iRow As Long
    
        DateRec = DTPicker1.Value
        LastName = Me.LastName.text
        FirstName = Me.FirstName.text
        FullName = LastName & " " & FirstName
        DrugCode = CInt(DrugCode.Value)
        Unit = CInt(Me.UnitsTextBox.Value)
        Amount = CDbl(Me.UnitsTextBox.Value)
        Price = CDbl(Me.Price.Value)
        
        'Date, Customer name,drug code, amount, price
        Set ws = Worksheets("Sales Record")
        ws.Select
        'the first empty row
        iRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
        ws.Cells(iRow, 1).Value = DateRec
        ws.Cells(iRow, 2).Value = FullName
        ws.Cells(iRow, 3).Value = DrugCode
        ws.Cells(iRow, 4).Value = Amount
        ws.Cells(iRow, 5).Value = Price
    End Sub
    The name of the combo boxes and text boxes are changed to the ones written above.
    ie. the drugcode combobox is named drugcode

    1. Somehow i keep getting an invalid qualifier for DrugCode = CInt(DrugCode.Value) and Price = CDbl(Me.Price.Value).
    2. before I added the Me. in front of the LastName.text I kept getting an invalid qualifier error as well. What does the Me. do?
    Last edited by DrowingInVBA; 03-18-2013 at 12:26 PM.

  2. #2
    Registered User
    Join Date
    03-16-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Invalid Qualifier

    Private Sub UserForm_Initialize()
      
      'Populate Color combo box.
      'Dim rngColor As Range
      'Set ws = Workbooks("Colours.xlsx").Worksheets("LookupLists")
      'Set ws = Worksheets("LookupLists")
      'For Each rngColor In ws.Range("ColorList")
      'Next rngColor
      
      Dim rngDrug As Range
      Dim ws As Worksheet
      'The workbook must be open. Setting the target worksheet in the workbook
      Set ws = Workbooks("MKDRUGEdit.xlsx").Worksheets("MKDRUG")
      For Each rngDrug In ws.Range("DrugCodeList")
        Me.DrugCode.AddItem rngDrug.Value
      Next rngDrug
    End Sub
    Now it throws an additional error that the method and data member cannot be found
    But the name of the combobox is DrugCode

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Invalid Qualifier

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-16-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Invalid Qualifier

    MKDRUGEdit.xlsxWorkbook1.xlsm
    This is the after^^

    The only thing that changed (when it stopped working) was the addtion of the submit button

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Invalid Qualifier

    The combobox on PurchaseForm is called 'DrugCode2' not 'DrugCode'.

    Also, on that form there is a textbox called 'Quantity' but in the code you have 'UnitsTextBox' in the Change event of that textbox, should that actually be 'Quantity'?

    Another problem, there is no named range DrugCodeList in either workbook.

    All of these things caused errors when I tried to open your forms.

    If I change 'DrugCode' to 'DrugCode2', change 'UnitsTextbox' to 'Quantity and change the code to populate the combobox to this,
      Dim ws As Worksheet
      'The workbook must be open. Setting the target worksheet in the workbook
      Set ws = ThisWorkbook.Worksheets("Drug Record")
        Me.DrugCode2.List = ws.Range("B2:B1514").Value
    I can open the purchase form.

    I've just realised the code you posted for the submit button is for the SalesForm, so I've been looking at the wrong form.:oops:

    The only problem I can see with that form is the DrugCodeList named range not existing.

    Mind you it's getting late and I've been looking at the wrong form for half an hour.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Invalid Qualifier

    don't use variables with the same names as your controls since it confuses the compiler. rename the variables and the invalid qualifier issue should be resolved
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Registered User
    Join Date
    03-16-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Invalid Qualifier

    Hi thanks guys the problem was with my naming of my variables

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Invalid Qualifier

    What about the named range?

  9. #9
    Registered User
    Join Date
    03-16-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Invalid Qualifier

    my variables had the same name as the textboxes or comboboxes.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    When I tried to open the userforms the code failed because a named range (DrugCodeList?) wasn't found in the xlsx workbook.

    Did you fix that?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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