Form Call with Variable String

schreinman

Registered User.
Local time
Today, 08:59
Joined
Oct 2, 2010
Messages
24
How do I need to code the "Forms!..." line so that SQL sees the value of strOriginForm instead of "strOriginForm"???

Code:

Dim strOriginForm
strOriginForm = frmName
Forms!strOriginForm!Project.Value = Me.Project.Value <<<<<<<<<<<<<

I've tried brackets, parentheses, quotes and double quotes around strOriginForm with no luck.
 
THANK YOU Master Larson!!!
 
How about this:

Forms(strOriginForm).strOriginalField = strAddNew

I couldn't find the right combination at work today. Do I delete the dot??? That's about all I haven't tried...

I am capturing the form and field that I am adding a new item to the pulldown menu for, and want to prepopulate the new value when I close the form that was used to create the record with the new value...

Thanks!!! in advance...
 
a control in a form is referenced with a bang !, not a dot

so its

Forms(strOriginForm)!strOriginalField = strAddNew

the dot operator would run a method, or sub IN the form


Forms(strOriginForm).somefunction
 
with the following code:

Forms(strOriginForm)!strOriginField = strNewAdd

I am still getting an error stating, "Database can't find the field 'strOriginField' referred to in your expression. [2465]"

So I still need something additional changed to caputure the value of strOriginField. Putting it in parenthesis, brackets, quotes etc. does not help...

Thanks for sticking with me on this one!

Eric
 
with the following code:

Forms(strOriginForm)!strOriginField = strNewAdd

I am still getting an error stating, "Database can't find the field 'strOriginField' referred to in your expression. [2465]"

So I still need something additional changed to caputure the value of strOriginField. Putting it in parenthesis, brackets, quotes etc. does not help...

Thanks for sticking with me on this one!

Eric
For using a variable as the field name you can use:
Code:
[B]Forms(strOriginForm).Controls(strOriginField).Value = strNewAdd[/B]
[B]
[/B]
 
We're getting SO CLOSE!!!

Now, can someone tell me how to select and item listed in a ComboBox instead of merely placing a value in the field of the ComboBox???

I have this:

Forms(strOriginForm).Controls(strOriginField).Value = strNewAdd

But want something that does this:

Forms(strOriginForm).Controls(strOriginField)."SelectListValue" = strNewAdd

THANKS!

Eric
 
You just set the combo to the value of the item you want. So if the combo has EmployeeID as the bound column and EmployeeName you can set it like:

Forms(strOriginForm).Controls(strOriginField).Value = 5

and it would select the employee with ID of 5. If you want to set it by the name you would use:

Forms(strOriginForm).Controls(strOriginField).Column(1) = "Ted Smith"
 
Sorry, I should have said ListBox instead of ComboBox...

This is what's happening:

I leave a form to go to another form to create a new value for a ListBox. The new record is created and I then go back to the original form with the new ListBox Value. My original form is tied to a dataset that is updated with the returned value and I want to pull a hidden field value associated with the newly returned value.

Simply pasting the new value in the ListBox does not update my hidden value. I must first find the new value in my ListBox and select it before my hidden value updates. That is why I want to select the list value instead.

I tried all variations with your proposed code for my scenario and get errors.

Now that I've painted a clearer(?) picture, is there another approach with code to do this?

Thanks.
 

Users who are viewing this thread

Back
Top Bottom