Results 1 to 4 of 4
  1. #1
    maya is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    2

    Issues with variable pathnames

    I'm not particularly experience with visual basic/ms access, so go easy on me



    I'm trying to write a function that opens a new form and sets certain values to those of the old form (specifically an identification number). I want both the new form name and the old form name to be arguments of function. However, I've run into problems trying to put the new form name variable into the form "path."

    I'm going for something along the lines of:

    Code:
    Public Function ChangeForms(NewForm As String, OldForm As String)
    DoCmd.OpenForm NewForm
    Forms!NewForm!ID = Forms!OldForm!ID
    DoCmd.Close acForm, OldForm, acSaveYes
    End Function
    However, in the third line NewForm and OldForm are interpreted as strings, not as variable names, so I get an error saying that the form "NewForm" could not be found. Any suggestions for how to solve this problem?

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    Forms(NewForm)!ID

    or

    Forms!(NewForm)!ID

    I can't remember offhand if you need the ! or not.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    maya is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    2
    It works without the bang. Thanks so much! BTW, I've been reading a lot of ms access forums, and your comments are always very helpful. Cheers!

    Maya

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help Maya, and welcome to the site! I didn't think it needed the bang, but I lost confidence and added the second one. Should have trusted myself.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. VBA debuggin issues....
    By sjl in forum Programming
    Replies: 1
    Last Post: 08-29-2011, 01:47 PM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 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