SQL form code not working properly

N

nybaseball22

Hello. I am using the following code in a form in OnCurrent and
AfterUpdate field. However, when it is initiated, I receive a debug
error. Any idea what I am doing wrong with this or how I can change
it to make it work?

Thanks.

On Current and Type_AfterUpdate Private subs

Private Sub Form_Current()
If Me.Type = "Oil" Then
Me.Gallon_Rate.Enabled = True
Me.Gallon_Quantity.Enabled = True
Me.Total_Cost.Enabled = True
Me.Bill_Period_Start.Enabled = False
Me.Bill_Period_End.Enabled = False
Me.KWH.Enabled = False
Me.Charges.Enabled = False
ElseIf Me.Type = "Electricity" Then
Me.Gallon_Rate.Enabled = False
Me.Gallon_Quantity.Enabled = False
Me.Total_Cost.Enabled = False
Me.Bill_Period_Start.Enabled = True
Me.Bill_Period_End.Enabled = True
Me.KWH.Enabled = True
Me.Charges.Enabled = True
ElseIf Me.Type <> "Oil" And Me.Type <> "Electricity" Then
Me.Gallon_Rate.Enabled = False
Me.Gallon_Quantity.Enabled = False
Me.Total_Cost.Enabled = False
Me.Bill_Period_Start.Enabled = True
Me.Bill_Period_End.Enabled = True
Me.KWH.Enabled = False
Me.Charges.Enabled = True
Else
' Any other options
End If
End Sub
 
A

Allen Browne

What error?

Does it say you cannot disable the control that has focus?

If so, SetFocus to something you will not disable.
 
N

nybaseball22

Thanks Allen. This helped, but I have a new problem. In my form, the
Type field is a DLookup. When I make a change, the Dlookup does not
change. Therefore, the form does not correctly change based on my
code. Does my code have something to do with the DLookup not working?

Thanks
 
A

Allen Browne

Best to start a new thread for a new question.

Calculated expressions can take some time to update.
You can force it with a Recalc if needed.

If that isn't suitable, you may want to use an unbound text box, and assign
the value in the events that require it to be updated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top