If Statement Problem

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I'm using this If statement on the "On Load" Event of a Form "Sales"
that has 2 command buttons on a Subform "Sales Details"
The statement always gives me the else answer even when the
LocationSales field = Bar
I can't seem to figure it out.
Thanks
DS


If Forms!Sales![LocationSales] = Bar Then
Forms!Sales.SalesDetails.Form!BarDelete.Visible = True
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = False
Else
Forms!Sales.SalesDetails.Form!BarDelete.Visible = False
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = True
End If
 
Just a guess, but as the form is loading, the focus is not set to the field
you are evaluating. You might try setting the focus to the field in question
prior to beggining your IF statement. You may even have to move all of this
code to the "On Open" event.
 
Larry said:
Just a guess, but as the form is loading, the focus is not set to the field
you are evaluating. You might try setting the focus to the field in question
prior to beggining your IF statement. You may even have to move all of this
code to the "On Open" event.

:

I'm using this If statement on the "On Load" Event of a Form "Sales"
that has 2 command buttons on a Subform "Sales Details"
The statement always gives me the else answer even when the
LocationSales field = Bar
I can't seem to figure it out.
Thanks
DS


If Forms!Sales![LocationSales] = Bar Then
Forms!Sales.SalesDetails.Form!BarDelete.Visible = True
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = False
Else
Forms!Sales.SalesDetails.Form!BarDelete.Visible = False
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = True
End If
I've tried On Open, On Load, On Current.
If I send the code from a listbox once the form is open it works.
Thanks
DS
 
DS said:
Larry said:
Just a guess, but as the form is loading, the focus is not set to the field
you are evaluating. You might try setting the focus to the field in question
prior to beggining your IF statement. You may even have to move all of this
code to the "On Open" event.

:

I'm using this If statement on the "On Load" Event of a Form "Sales"
that has 2 command buttons on a Subform "Sales Details"
The statement always gives me the else answer even when the
LocationSales field = Bar
I can't seem to figure it out.
Thanks
DS


If Forms!Sales![LocationSales] = Bar Then
Forms!Sales.SalesDetails.Form!BarDelete.Visible = True
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = False
Else
Forms!Sales.SalesDetails.Form!BarDelete.Visible = False
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = True
End If
I've tried On Open, On Load, On Current.
If I send the code from a listbox once the form is open it works.
Thanks
DS

Use a simple debug technique that should make it easy.

Debug.Print "LocationSales: " & Forms!Sales![LocationSales]
Debug.Print "Bar: " & Bar

Put these two lines just above your If statement. Open your form. Check
the immediate window. The problem will probably be apparent.
 
Randy said:
Larry wrote:

Just a guess, but as the form is loading, the focus is not set to the
field
you are evaluating. You might try setting the focus to the field in
question
prior to beggining your IF statement. You may even have to move all of
this
code to the "On Open" event.

:



I'm using this If statement on the "On Load" Event of a Form "Sales"
that has 2 command buttons on a Subform "Sales Details"
The statement always gives me the else answer even when the
LocationSales field = Bar
I can't seem to figure it out.
Thanks
DS


If Forms!Sales![LocationSales] = Bar Then
Forms!Sales.SalesDetails.Form!BarDelete.Visible = True
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = False
Else
Forms!Sales.SalesDetails.Form!BarDelete.Visible = False
Forms!Sales.SalesDetails.Form!OtherDelete.Visible = True
End If

I've tried On Open, On Load, On Current.
If I send the code from a listbox once the form is open it works.
Thanks
DS


Use a simple debug technique that should make it easy.

Debug.Print "LocationSales: " & Forms!Sales![LocationSales]
Debug.Print "Bar: " & Bar

Put these two lines just above your If statement. Open your form. Check
the immediate window. The problem will probably be apparent.
Wow! Thanks that is really cool! I'll have to move it elsewhere. It
never ends.
Thanks
DS
 
Back
Top