Writing data to a variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi:
I'm fairly stuck on writing data to a field which is pointed to by a variable. Code looks like this:
---------------------------
Dim myfield As Control
mytext = Combo27
mystring = "M" & mytext
Forms!contacts!Outputfield = mystring
Set myfield = Forms!contacts!Outputfield
DoCmd.GoToControl myfield
myfield = "ZZZ"
 
You want to refer to the field that is named "M" plus whatever is in
Combo27, and assign the value "ZZZ" to that control?

Easiest to refer to the control by name, as part of the Controls collection
of the form:

Dim strFieldName As String
strFieldName = "M" & Me.Combo27
Me.Controls(strFieldName) = "ZZZ"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SueH said:
Hi:
I'm fairly stuck on writing data to a field which is pointed to by a
variable. Code looks like this:
---------------------------
Dim myfield As Control
mytext = Combo27
mystring = "M" & mytext
Forms!contacts!Outputfield = mystring
Set myfield = Forms!contacts!Outputfield
DoCmd.GoToControl myfield
myfield = "ZZZ"
is concerned, but doesn't work when trying to write data to the field.
 
Hi Allen:
Thanks so much for taking the time to sort me out - of course it has worked and saved me a lot of grief. Also had a peek at your website - excellent !
 
Back
Top