Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Two questions re: coding names

    I am reading Access 2000 Crashcourse book. In the code listings, one can find the following code:
    Me![TableName].SetFocus (tablename is a textbox)

    When I try the following:
    Me.TableName.SetFocus
    VBA allows it and it works just as well.
    Under what circumstances would I use the first method of coding and when the second?

    There is a table called Payees with (what appears) two fields: Payees and Selected. There's also a little button with a plus in front of each Payee listed in the table.
    When I expand the record, I can see a bunch of transaction details in a table like structure (maybe a query result?)

    In an import routine listing is the following code:
    Do Until TransTB.EOF
    PayeeTB.AddNew
    PayeeTB![Payees] = TransTB![Payees]

    Here PayeeTB.Payees does not work. I suppose because it refers to a field name in a recordset based on Payees table.

    My question is: Does [Payees] refer to a single field in the Payees recordset or is this a method of coding that results into importing data into multiple fields? (I can't check the import data because there is no file with import data to look at).

    Hope somebody can clarify this for me a bit.

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two questions re: coding names

    Hi,

    You use the brackets on anything you define yourself.
    Me![TableName].SetFocus is the correct notation.
    Me is a preserved word in VBA, so it should not be between brackets.
    TableName is the name you gave to the table, this should be between brackets.
    SetFocus is a method of the table object and should not be between brackets.
    Using the brackets enables you to use spaces in naming your objects. I never do that, becaus I think it makes your code unreadable. I normally use capitals (for instance in tblThisIsMyTable).

    The + sign in front of your records indicates there is a one to many relation ship between the two tables. It is not an indication of a query!
    If you click the + it simply opens the many branch of the relationship.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two questions re: coding names

    Thanks Bart.
    That clarifies the coding conventions for me.

    As for the code I used, it is straight from the book. I agree, I also would use LNC naming convention for anything but fields as indicated by Charlotte. I like grugeon's use of fld in front of the field name. I am going to experiment with that a bit.

    You've also been helpful re: second question. If I understand correctly then, this sample code snippet I included only imports data into the single field called Payees. (I wonder why they called that routine: ImportChecks)

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two questions re: coding names

    You included this code:

    Do Until TransTB.EOF
    PayeeTB.AddNew
    PayeeTB![Payees] = TransTB![Payees]

    This is not complete! Looking at this code I think the following is happening:

    There are two recordsets:
    PayeeTB and TransTB
    For each record in recordset TransTB a record is added to recordset PayeeTB.
    The content of the field payees is copied from recordset TransTB to PayeeTB.
    There must be more code, this is not complete!

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two questions re: coding names

    Yes Bart, you're correct on both counts.

    There is a lot more code.
    I didn't bother to include it because I was primarily concerned with the meaning of:
    PayeeTB![Payees]=TransTB![Payees]
    Since the complete procedure is called ImportChecks, I was expecting it to only import cheques (Cdn, checks for US) not just a single field containing Payee names.

    It's quite hard at times to read other people's code. I have since come to recognize that this procedure in the book I am referring to actually does three separate things:
    1. You can import Payee names
    2. You can import Bank accounts
    3. You can import cheque transactions.
    Finally, you can use three different import file formats: Access db, xls and csv. It was all a bit confusing for this greenhorn.
    [img]/w3timages/icons/sick.gif[/img]
    Thanks for helping me out!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •