Results 1 to 11 of 11
  1. #1
    AishlinnAnne is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Aug 2016
    Location
    Mass
    Posts
    52

    Question Learning VBA - specifically "Hello, world!"

    Hi, I am learning about VBA as I go and the program I will need to use it for is Access. I started creating a database for work, having never even opened it before. I was thinking, "oh I am a wiz at Excel," but realized real quick, that knowing excel doesn't mean anything when learning Access.

    There are not a lot of tutorials on Access VBA, AT ALL. Everything that I could find, assumed that I already knew how to run VBA and was just teaching me certain operations. But the problem there is, I know NOTHING about how to write code or anything. So I started tutorials on Visual Basic, itself, not for Access. I know there are some differences, but from what I understood it was more about language and how to call certain object, not the general structure of writing code. Like how to know what Private/Public, Sub/Function, etc.. means. I learned a lot of VBA jargon that has already helped me understand a little bit.

    Problem being, on my very first attempt to create the simple, Enter "Hello, world!" into a textbox after clicking a command button.
    So I...
    1. Created a blank form and went to Design View
    2. Inserted blank textbox
    3. Inserted command button
    4. Renamed as needed, (Textbox1/Command1)
    5.Changed command button to say OK as caption
    6. Opened VBA
    7. Selected Command1 out of object list box and Click out of procedure list box
    8. Typed: textbox.Text = "Hello, world!" between Sub and End Sub

    Code simply reads:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Command1_Click()
        Textbox1.Text = "Hello, world!"
    End Sub

    I keep getting an error message that says:
    "The expression On Click you entered as the event property setting produced the follow error: A problem occurred while Microsoft Access was communicating with the OLE server or ActiveX Control.
    *The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
    *There may have been an error evaluating the function, event, or macro."


    I have tried researching and figuring out on my own, but I can't seem to find an answer.

    Does anybody know why this would be happening?



    Thank you!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You now need to read about control properties.

    You are using the "Text" property for the text box control. You cannot set the text property unless the control has focus. The "Text" property is the uncommitted value for the control.
    The default property (for mouse controls) is the "Value" property. Since it is the default property, normally it is not written - saves typing.

    Try
    Code:
    Private Sub Command1_Click()
        Me.Textbox1.Value = "Hello, world!"
    End Sub
    or
    Code:
    Private Sub Command1_Click()
        Me.Textbox1 = "Hello, world!"
    End Sub

  3. #3
    AishlinnAnne is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Aug 2016
    Location
    Mass
    Posts
    52
    Quote Originally Posted by ssanfu View Post
    You now need to read about control properties.
    Thank you, I have actually tried the bottom one and it hasn't worked. I just tried the top suggestion you provided and that isnt working either.
    I created a blank form, changed it to design view, added a command button, added a textbox, made sure they were both enabled, renamed them, then opened vba and added the above code.

    Am I missing a step?

    Thanks again!

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    I just tried the code and didn't get any errors. See attached
    Attached Files Attached Files

  5. #5
    AishlinnAnne is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Aug 2016
    Location
    Mass
    Posts
    52
    Quote Originally Posted by ssanfu View Post

    I just tried the code and didn't get any errors. See attached
    It worked!! I KNOW that I tried that exact code yesterday, that is so bizarre!!!!
    My work internet is a little strange, I wonder if it had to do with how I was connected to the network?
    Either way, thank you!!!

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I'm sure I posted this playlist previously in one of your posts, but here is a free youtube series on Access/vba programming by Steve Bishop. There are over 70 videos.
    Look at the playlist, and start with video #1. Try it, repeat as necessary. Let us know your progress.
    Good luck.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What orange said....

  8. #8
    AishlinnAnne is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Aug 2016
    Location
    Mass
    Posts
    52
    Quote Originally Posted by orange View Post
    I'm sure I posted this playlist previously in one of your posts, but here is a free youtube series on Access/vba programming by Steve Bishop. There are over 70 videos.
    Look at the playlist, and start with video #1. Try it, repeat as necessary. Let us know your progress.
    Good luck.
    Thank you again! I am sorry for double posting some of this. I have been having a hard time trying to stay on track bouncing around from example to example trying to learn.
    I am on Chapter 9 of this Steve Bishop guy, and so far this has been the best tutorial yet. So again, thank you!!

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Glad you are finding the Steve Bishop tutorials useful.
    Go luck with your "learning".
    Post if you have specific problems.

    For a brief change you might want to watch the Dr. Soper Database videos. I recommend #1,2 and 4 until you're comfortable with the concepts--then go back to the Programming series by Steve.

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by AishlinnAnne View Post

    ...I was thinking, "oh I am a wiz at Excel," but realized real quick, that knowing excel doesn't mean anything when learning Access...
    Unfortunately, it does mean something, when learning Access...it means it's probably going to be more difficult for you to learn Access than for someone straight off the street with no experience in Access or Excel!

    The problem is not simply that VBA for Excel is different from VBA for Access; in addition to this fact, Access has many Properties and Functions with the same names as Properties and Functions in Excel...but they often perform different tasks and are implemented differently!

    The perfect example of this is the one you've already discovered... .Text vs .Value! In Excel, if you have a Textbox named MyControl, and you write

    MyControl.Text = "ExcelGeek"

    Excel also assigns "ExcelGeek" to MyControl.Value, as well! And the former can be done basically anywhere in the code module, regardless of which Control has Focus.

    In Access, as has been explained, the two Properties are entirely different, and have to be implemented differently.

    Text is the data that appears in the Control when the Control has Focus...it is not the Value of the Control, at that time, and can only be assigned when the Control actually has Focus. Value, on the other hand, can be assigned whether the Control has Focus or not ! And just to muddy the waters even more (as if this were needed!) when Focus moves off of the Control to another Control, the Text data becomes the Value data!

    So, basically, when working in Access...you need to forget everything you know about Excel...not something that is easy to do!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    AishlinnAnne is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Aug 2016
    Location
    Mass
    Posts
    52
    Quote Originally Posted by Missinglinq View Post
    VBA for Excel is different from VBA for Access
    Well, when I said, "oh Im a wiz at excel," thats what i THOUGHT.
    I have never actually used VBA in anything, I really am nowhere near as good at it as I thought I was.

    Which is becoming clearer and clearer to me, haha.
    But hey, that just leaves more to learn, right? lol

    Thank you all!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-12-2016, 12:58 PM
  2. Replies: 2
    Last Post: 12-23-2015, 09:32 PM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  5. Replies: 11
    Last Post: 03-29-2012, 02:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums