Results 1 to 4 of 4
  1. #1
    MWMike is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Long Island, NY
    Posts
    18

    Red face Visual Basic / Acces Form differences


    Hey all,

    I'm pretty used to visual basic and assumed that most of the Access form controls would be similar, but upon trying to do some really basic stuff in VBA, I end up getting errors. For example:
    Private Sub Command1_Click()
    Me.TextBox1.Text = "sometext"
    End Sub
    This code gives me an error, saying something like the "focus" can only be on one thing at a time. Does this mean the form controls in Access can only be bound to data from the tables/queries? I figure this is a pretty important point that will help me figure out how best to use Access forms.

    Thanks for your help

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    while focus can only be on one control at a time; it doesn't seem like your code should trigger anything related to focus. So on this point I share your confusion. Do try:

    Me.TextBox1 = "sometext"

  3. #3
    NoellaG's Avatar
    NoellaG is online now Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    884
    Hi Mike,

    you should have used the "Value" property in stead of the "Text" value of the text box.
    The "Value" property returns (or sets) the last saved value of the field bound to the control, and is always available. The "text" property returns the actual text in the box and is only available when the control has the focus.
    So before you can access the "text" property you have to use the "SetFocus" method to move the focus to that control.

    It's easier to use the "Value" property, and as the "Value" property is the default property of a control, you can leave this out your expression, as in the example NTC provided.

    grNG

  4. #4
    MWMike is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Long Island, NY
    Posts
    18
    Sorry guys, it took a while before I could get back to my project. Both of your suggestions worked! I don't know why it would be different, but then again I'm used to VB6, things may have changed.

    OK, this gives me confidence that I can still do normal VB stuff with the Access forms. The reason I was asking is because I'm trying to do a sort of hybrid database / file organizer. I am keeping a lot of data in the database but individual files will be organized on the server by the VB code. Then I will store hyperlinks to the files in the database.

    Thanks!

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

Similar Threads

  1. Using Access Instead of Visual Basic
    By dinz in forum Programming
    Replies: 2
    Last Post: 12-19-2019, 10:33 AM
  2. Can't see visual basic code
    By Michele Keck in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:31 AM
  3. Query in visual basic
    By Lucas83 in forum Programming
    Replies: 1
    Last Post: 06-10-2010, 11:00 AM
  4. Locking form with Visual Basic
    By rev_ollie in forum Forms
    Replies: 4
    Last Post: 04-29-2010, 07:27 AM
  5. Record Value in Visual Basic
    By chrismec in forum Programming
    Replies: 3
    Last Post: 12-09-2009, 04:14 PM

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