• Operand without operator error message

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Operand without operator error message

    Author
    Topic
    #501617

    I’m trying to have a MsgBox open up with a text input in to enter a date. I took the code directly from Microsoft and I get the operand without operator error message. Below is my code. Can someone please help?

    Code:
    Dim StartDate As Date    ‘ Declare variables.
    Dim Msg
    StartDate = InputBox(“Enter a date”)
    Msg = “Yield ” & DateDiff(“m”, StartDate, Now()) 
    MsgBox Msg

    Thank you to whoever can help!:confused:

    Viewing 15 reply threads
    Author
    Replies
    • #1522784

      For one thing, you haven’t defined the type of Msg so it defaults to the type variant but you really want it to be a text value so you should say Msg As String. In addition, it may well be that Msg is a reserved word in VBA. I would give it a different name, such as UserPrompt.

      But the issue with using the MsgBox function is that you cannot enter data into a MsgBox. What would do the trick is the InputBox() function – see InputBox() as one of many references for the details on how it is used. If you want a more polished solution than the InputBox() function can give you, then you can use a regular form in Access, but in the PopUp and Modal format to do error checking and other useful things to the data entered.

    • #1522785

      Enginerd,

      It works on my Access 2010 with the minor changes shown:
      41714-AccessTestMsg

      Note: I entered 5/1/2015 in the inputbox.

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1522791

      HTH,

      I tried that and it kicks back with the “Dim” at StartDate as the operand without operator. (If that makes sense) I have a feeling it will also do that with the Msg as String. I am using Access 2013, so I’m not sure if that has an effect?

    • #1522799

      Enginerd,

      FYI: HTH = Hope This Helps!

      Could you please post the entire procedure so we can see if there is something else in play here? :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1522801

      I’m trying to have a MsgBox open up with a text input in to enter a date. I took the code directly from Microsoft and I get the operand without operator error message. Below is my code. Can someone please help?

      Code:
      Dim StartDate As Date    ‘ Declare variables.
      Dim Msg
      StartDate = InputBox(“Enter a date”)
      Msg = “Yield ” & DateDiff(“m”, StartDate, Now()) 
      MsgBox Msg

      Thank you to whoever can help!:confused:

      that code runs for me without any amendments in Excel 2010.

      Have you definitely lifted the text exactly as it appears in your program? ‘Operand without operator’ suggests you may have a stray character like ‘ or , somewhere in your code!

    • #1522803

      I am positive. that is identical to what I am trying to run.

    • #1522806

      Enginerd,

      I just tried running your exact code on Access 2016 and it works perfectly.
      There MUST be something that you have differently or Access 2013 has a bug!

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1522808

      does it make a huge difference if i try to have this code run on a query vs a form?

    • #1522811

      Enginerd,

      As I said before we need to see the whole context otherwise we’re shooting in the dark with a code snipit that seems to work just fine. :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1522813

      41715-Capture

      These are my fields along with what I want to show up in my query. I am trying to write this code from completion date.

    • #1522886

      Enginerd,

      So if I read this correctly you are trying to get the number of months from Start Date to Completion Date or maybe the current date? If this is so you should add a calculated field to your query to show this information. HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1523479

      Kind of. I’m trying to allow for an input so for example i can input 5/1/2015 and current date and it will return all fields within that range. Trouble is i need the 5/1/2015 field to be changeable.

    • #1523501

      Enginerd,

      Ok so you want the range of dates between an inputted data and today. So you want all records that have a completion date in that range? :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1523528

      Yes. Exactly. If that is possible

    • #1523533

      Enginerd,

      In the Criteria Row for the Completion Date enter:

      Code:
      >=[Enter Period Beginning Date] And <=Date()
      

      When you run the query it will prompt for the Period Beginning Date.

      Sample Run:
      41750-Enginerd
      Results on my Test File:
      41751-Enginerd1

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1523536

      thank you so much! that works perfectly!

    Viewing 15 reply threads
    Reply To: Operand without operator error message

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: