By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,222 Members | 1,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,222 IT Pros & Developers. It's quick & easy.

Forms![variable]! ??

P: 36
Hi again,

I would like to learn how to make this work
With a click of a button I copy and rename a table and form from templates
the problem is that I want relink the new form to the new table (instead of being linked to the template)

Access keeps telling me that NewName! form does not exist. Its taking the name literally instead of its value. Could anyone help

Private Sub Command6_Click()
NewName = Username.Value

DoCmd.CopyObject , NewName, acTable, "template"
DoCmd.CopyObject , NewName, acForm, "template"

Forms!NewName!ID.ControlSource = [NewName]![ID]
Nov 26 '06 #1
Share this Question
Share on Google+
10 Replies


Expert 5K+
P: 8,434
Is NewName a variant? Perhaps it would make a difference if it were a string.
Nov 26 '06 #2

Expert 5K+
P: 8,434
Also, in this line of code
Expand|Select|Wrap|Line Numbers
  1. Forms!NewName!ID.ControlSource = [NewName]![ID]
I think (pretty rusty on this) that you can replace Forms!NewName with Forms(NewName)
Nov 26 '06 #3

NeoPa
Expert Mod 15k+
P: 31,660
Also, in this line of code
Expand|Select|Wrap|Line Numbers
  1. Forms!NewName!ID.ControlSource = [NewName]![ID]
I think (pretty rusty on this) that you can replace Forms!NewName with Forms(NewName)
Not only can you, but you must.
the Collection! format requires the actual name to be used. As you only have a variable containing the name, you can only use the Collection() format to refer to it.
Nov 26 '06 #4

P: 36
Is NewName a variant? Perhaps it would make a difference if it were a string.

NewName is a value taken from a input box. its supposed to represent a newuser who is being created with the end result of having his own table and form
Nov 26 '06 #5

P: 36
I tried several methods of writing this but I can't seem to access the field ID using
forms()

I tried forms(NewName)!ID.Controlsource, forms(NewName!ID.Controlsource)

Trying this forms(NewName.ID).ControlSource would bring on my code window but without telling me whats the error
Nov 26 '06 #6

Expert 5K+
P: 8,434
I tried several methods of writing this but I can't seem to access the field ID using forms()
I tried forms(NewName)!ID.Controlsource, forms(NewName!ID.Controlsource)
Have you tried this variation?
Expand|Select|Wrap|Line Numbers
  1. forms(NewName).ID.Controlsource
(I underlined the difference).
Nov 26 '06 #7

PEB
Expert 100+
P: 1,418
PEB
Have you tried this variation?
Expand|Select|Wrap|Line Numbers
  1. forms(NewName).ID.Controlsource
(I underlined the difference).
I think trhis may provoke an error

try also

Expand|Select|Wrap|Line Numbers
  1. forms(NewName).("ID").Controlsource
  2.  
Nov 26 '06 #8

P: 36
Have you tried this variation?
Expand|Select|Wrap|Line Numbers
  1. forms(NewName).ID.Controlsource
(I underlined the difference).
Once I type forms(NewName). <- [with the dot] then a list of options show up which indicate different properties of the form and non indicate a away to access a field. Ocfourse going ahead and continuing typing as ID.Controlsource will produce error.

I feel frustrated

I wish I could find somesort of reference to every and (I mean every) function, command, and other things that does not seem to be written any where
Nov 26 '06 #9

Expert 5K+
P: 8,434
Once I type forms(NewName). <- [with the dot] then a list of options show up which indicate different properties of the form and non indicate a away to access a field. Of course going ahead and continuing typing as ID.Controlsource will produce error.
I wouldn't be too sure of that - it might be worth a try.

I think this comes down to the old issue of late- versus early-binding. In this case, VB cannot provide the control names in the list of attributes for the form, because it won't know until runtime which form it is. All it can check is the general syntax of the statement. At runtime, it will have to verify that the control you referred to actually exists.

Also, is there a Controls property in the list? If so, you might try something like
Expand|Select|Wrap|Line Numbers
  1. forms(NewName).Controls("ID").ControlSource
I feel frustrated
Welcome to programming. :)

I wish I could find somesort of reference to every and (I mean every) function, command, and other things that does not seem to be written any where
I'm pretty sure it is all reasonably well documented, but can be difficult to find sometimes.
Nov 26 '06 #10

NeoPa
Expert Mod 15k+
P: 31,660
Killer's absolutely right on this.
Try typing it anyway.
The list it prompts you with is NOT necessarily the full list!
Nov 26 '06 #11

Post your reply

Sign in to post your reply or Sign up for a free account.