?
Solved

How to sue Form name in variable - Access

Posted on 2011-10-20
3
Medium Priority
?
271 Views
Last Modified: 2012-05-12


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

0
Comment
Question by:Karl001
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 37000393
try

Dim fForm As Form
Dim cmpMonth As Integer
   
set fForm = Forms!frm_training
0
 

Author Closing Comment

by:Karl001
ID: 37000412
Thanks
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37000431
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question