Thread: [Solved] MS Access Module help please
View Single Post
 
Old 12-17-2024, 08:01 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Instead of repeating that block of code each time, you create a sub like:
Code:
Sub Trucks(t As Long)
Dim i As Long, j As Long
For i = 1 To 17
  For j = 1 To 10
    Me(Chr(64 + j) & i).Enabled = t >= j
  Next
Next
End Sub
and assuming Me.NumTrucks returns 0 when empty, then call the Trucks sub with code like:
Code:
Call Trucks(Me.NumTrucks)
Alternatively, if Me.NumTrucks doesn't return 0 when empty, you might call the Trucks sub with code like:
Code:
Call Trucks(CLng(Me.NumTrucks))
or, failing that:
Code:
Dim t As Long
If IsNull(Me.NumTrucks) Then
  t = 0
Else
  t = Me.NumTrucks
End If
Call Trucks(t)
PS: For Access related discussions, you should visit AccessForum.net: Microsoft Access Forums
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote