Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enabling/disabling controls in a chain

Status
Not open for further replies.

galorin

MIS
Nov 22, 2007
154
GB
I have 5 boxes that take dates. I currently use a popup calendar with code that looks like this (cboOrig is a global Combobox, Orig is a global string)

Code:
Private Sub Ready1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
Set cboOrig = Me.ready1
Orig = "Ready1"
Me.QuoteCal.Visible = True
Me.QuoteCal.SetFocus
If Not IsNull(cboOrig) Then
 QuoteCal.Value = cboOrig.Value
Else
 QuoteCal.Value = Date
End If

End Sub

then when the calendar is clicked
Code:
Private Sub QuoteCal_Click()

If QuoteCal.Value > Date Then
 MsgBox "Can't postdate checks", vbExclamation
 Exit Sub
End If

cboOrig.Value = QuoteCal.Value

Select Case Orig
 Case Is = "Ready1"
  Me.Return1.Enabled = True
  Me.JobForward.Enabled = False
 Case Is = "Return1"
  Me.ClientChk.Enabled = True
  Me.SiteAmend.Enabled = True
  Me.ProcFin.Enabled = True
 Case Is = "ClientChk"
  Me.ClientSiteApr.Enabled = True
 Case Is = "ClientSiteApr"
  Me.Return2.Enabled = True
End Select

cboOrig.SetFocus
QuoteCal.Visible = False
Set cboOrig = Nothing
End Sub

As you can see, on the selection of a date from the calendar, it sets the combobox to that value, then enables the next in the chain. Design spec says that in no instance can a date be input out of order. I have another function that when a button is clicked, adds all the boxes with a date in them into the database, and locks the fields for input. The next box without input is then enabled, ready for input. User error is fixed by clearing out all dates (ham-fisted, but effective).

So far it works OK, but not best. I got a feature request for a way of populating all the remaining fields with a set date, at two points in the process. No special flags have to be set, and I have a mostly-working setup, but it is a mess. At this stage, I either need to re-implement, or bodge it all.

I am looking for a better way of chaining the enabling of controls based on the state of the previous control. From my limited programming base, this doesn't seem to be something that VBA is geared for, unless I've missed something. Help/suggestions welcomed.
 

I think you can control the enabled property with conditional formatting.

Randy
 
well in the easiest example, if all five combo's are on one form, when you create a new record, or enter the form you can easily set all but the first to enabled = false

then as you select each box you can enable the next combo with the after update event maybe??

And if its the fact that the date is picked after its picked from a calendar, just add to the end of the calendar on click to run a function.....

in this function simply have
if not isnull(combo1) combo2.enabled = true
if not isnull(combo2) combo3.enabled = true
if not isnull(combo3) combo4.enabled = true
if not isnull(combo4) combo5.enabled = true

am i missing what you have requested??

cheers

daveJam

even my shrink says its all your f#@/ing fault
 
Sorry for the delay, tek-tips isn't sending reply notifications to me, or else they're getting labeled as spam.. odd. Anyhow..

DaveJam, I have re-visited my code and done something similar to what you have explained. While the date is primarily chosen from a calendar, it is also possible to go back and delete dates after they hve been input, so date #3 can be present, but date #2 may be blank or incomplete. It is also possible to manually enter dates, and I have a sub that only accepts {backspace|delete|[0-9]|\} (No regex matching, that would be an absolute pain in the neck)

I'm making progress, and have decided on an array of controls, to give me access to the properties of each of my controls. Taken a while to get working as most of what I read online said it couldn't be done. Code isn't ready to be published yet.

So far, my users have had training, and still do silly things with the software that has made it break on occasion. These measures are to keep it from dying or doing something wrong should my users do something stupid.
 
I just noticed a problem, here is the code that I believe may be in question
Code:
Private Sub Ready1_KeyUp(KeyCode As Integer, Shift As Integer)
If IsNull(Me.ready1.Text) Or Len(Me.ready1.Text) <> 10 Then
 Me.Return1.Enabled = False
 Me.JobForward.Enabled = True
Else
 Me.Return1.Enabled = True
 Me.JobForward.Enabled = False
 Me.JobFwdDate.Enabled = False
End If
End Sub

JobForward is a tickbox that should only be enabled when Return1 does not have a date in it, JobFwdDate is the datefield connected to the tickbox, Return1 is the next date in the chain of dates. The code behaves as it should, except for one instance.

If the text in Ready1 is highlighted, and the delete key or backspace key is pressed, this event does not fire. If I press the same key again, then this sub is called. Why is this, and how do I get around it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top