0
私は月ごとにプロジェクトのステータスを表示するフォームを作成しました。私は列/コントロールボックスのプロパティを毎月の開始時に一度更新したい(年が進むにつれて現在の月を再表示する)。将来の月にはまだデータがないので、私は次のコードを書いた。可視プロパティを設定する特定の命名構造を持つループスルーコントロール
Public Function updateProgressForm()
Dim currentMonth As String
Dim currentYear As Long
Dim txtDate As String
Dim todaysmonth As Long
Dim txtboxMonth As Integer
Dim txtboxName As String
Dim txtboxLabel As String
todaysmonth = Month(Now())
currentMonth = MonthName(todaysmonth, 3)
currentYear = Year(Now())
txtDate = currentMonth & " " & currentYear
DoCmd.OpenForm "IndProgressTracking", acDesign, , , , acWindowNormal
Forms!IndProgressTracking!Month12.ControlSource = txtDate
Forms!IndProgressTracking!Month12Label.Caption = txtDate
For txtboxMonth = 1 To 12 Step 1
txtboxName = "Month" & txtboxMonth
txtboxLabel = txtboxName & "Label"
If IsNull(txtboxName) Then
txtboxName.Visible = False
txtboxLabel.Visible = False
Else
txtboxName.Visible = True
txtboxLabel.Visible = True
End If
Next
txtboxName = "Month1"
Forms!IndProgressTracking.Controls!txtboxName.Visible = True
End Function
私にエラーを出す部分は、txtboxName.Visibleです。これは無効な修飾子です。したがって、私は最後の2行を代わりに試みましたが、最後の行(終了関数の前に)は、私が(txtboxName
)を参照したコントロールを見つけることができないと述べています。私は毎月のテキストボックスとラベルを持っているので、Forループを使用して単純化することを望んでいたコントロール名を使用してそれぞれを個別に呼び出す必要がある場合、それほど大きな問題ではありません。どんな提案も歓迎です!
おかげ@HansUp - 私はいつもそれだけで1行だ場合でも、私のコードをテストし、時には後ろに正しい参照を置くことを忘れてみてください。 –