Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    1

    Wink Unanswered: Constructing a form name using a string

    Hi All,

    I am trying to clean up a section of code which updates the value in one of a set of data entry subforms. At present I am using a whole bunch of if statements and have the name of each particular subform form in full as follows...

    Dim LayerNumber
    LayerNumber = Forms!frmObservations.Form!LayerNumber

    If LayerNumber = 1 Then
    Forms!frmObservations!fsubObservationsLayer1!fsubS ppObservations.Form!SpeciesID.Requery
    Let Forms!frmObservations!fsubObservationsLayer1!fsubS ppObservations.Form!SpeciesID.Value = UpdateSpeciesID
    End If

    If LayerNumber = 2 Then
    Forms!frmObservations!fsubObservationsLayer2!fsubS ppObservations.Form!SpeciesID.Requery
    Let Forms!frmObservations!fsubObservationsLayer2!fsubS ppObservations.Form!SpeciesID.Value = UpdateSpeciesID
    End If

    If LayerNumber = 3 Then '... etc. etc.

    I would like to replace it with something that constructs the form name as below...

    Dim FormString As String
    Dim aoCorrectForm As Access.AccessObject
    Dim LayerNumber
    LayerNumber = Forms!frmObservations.Form!LayerNumber

    FormString = "frmObservations!fsubObservationsLayer" & _
    LayerNumber & "!fsubSppObservations.Form!SpeciesID"
    Set aoCorrectForm = Forms(FormString)

    aoCorrectForm.Requery
    Let aoCorrectForm.Value = UpdateSpeciesID


    ...but I am getting a "could not recognise form" message - which indicates that the syntax is not correct for the Form("formname") method of naming a form. I have tried many slight variations on the above to no avail.

    Any ideas?

    Many Thanks,

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Dim LayerNumber
    Dim myForm As Form
    Set myForm = Forms!frmObservations.Form!LayerNumber

Posting Permissions

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