How to sue Form name in variable - Access



Form + button.

I would like to use  a name form in a variable and then, use the variable in the code (below)

fForm = Forms.frm_training
 or
fForm = Me

doesn't work

thanks
Click button event:    

Dim fForm As Form
Dim cmpMonth As Integer
    
fForm = Forms.frm_training

cmpMonth  = 0
Do While cmpMonth < 4

   cmpMonth = cmpMonth + 1
   If fForm("month" & cmpMonth & "Year").Value = 0 Then
      fForm("month" & cmpMonth & "Year").Value = 
            Year(Me.txtDateExtension)
      fForm("month" & cmpMonth & "No").Value = 
            Month(Me.txtDateExtension)
      fForm("month" & cmpMonth & "Day").Value = 0
      fForm("month" & cmpMonth & "Hour").Value = 0
   End If
Loop

Open in new window

Karl001Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
try

Dim fForm As Form
Dim cmpMonth As Integer
   
set fForm = Forms!frm_training
0
 
Karl001Author Commented:
Thanks
0
 
Rey Obrero (Capricorn1)Commented:
if the button you are using is on the same form, just do this


Click button event:    

 
Dim cmpMonth As Integer
   
 

cmpMonth  = 0
Do While cmpMonth < 4

   cmpMonth = cmpMonth + 1
   If me("month" & cmpMonth & "Year").Value = 0 Then
      me("month" & cmpMonth & "Year").Value =
            Year(Me.txtDateExtension)
      me("month" & cmpMonth & "No").Value =
            Month(Me.txtDateExtension)
      me("month" & cmpMonth & "Day").Value = 0
      me("month" & cmpMonth & "Hour").Value = 0
   End If
Loop
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.