Changing a the value of a combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hallo

I am having the following problem with a combo box it linked to a table and
I can select a name from the table works fine then I have the statement
afterupdate to set a field called QTY to 1 but when I erase the combo box
again I want it to set the QTY field back to 0 it does not do that

I have tried the following

1)
if isnull([forms]![Sales]![Combo]) then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

2)
if [forms]![Sales]![Combo] = null then Even tryd = ""
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

It just does not change it back to a 0 it leaves it at 1

Does any one have any ideas on what i am doing wrong?

Regards
Markus
 
Try this

If isnull([forms]![Sales]![Combo]) or [forms]![Sales]![Combo]="" then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
end if
 
It does not work

Here is the exact code i use

Private Sub Card_Name_AfterUpdate()
Me![Card Name] = [Card Name]

[Card Price] = DLookup("[Card Price]", "Card Details", "[Card Name]=
Forms![Card Sales]![Card Name]")
If IsNull(Card_Name) Then
Exit Sub
End If

Me![Card Price] = [Card Price]

If IsNull([Forms]![Card Sales]![Card Name]) Or [Forms]![Card Sales]![Card
Name] = "" Then
[Forms]![Card Sales]![Qty] = 0
Else
[Forms]![Card Sales]![Qty] = 1
End If

End Sub

It will add the 1 but if you erase the combo box it does not set a 0 then

Ofer said:
Try this

If isnull([forms]![Sales]![Combo]) or [forms]![Sales]![Combo]="" then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
end if

Markus said:
Hallo

I am having the following problem with a combo box it linked to a table and
I can select a name from the table works fine then I have the statement
afterupdate to set a field called QTY to 1 but when I erase the combo box
again I want it to set the QTY field back to 0 it does not do that

I have tried the following

1)
if isnull([forms]![Sales]![Combo]) then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

2)
if [forms]![Sales]![Combo] = null then Even tryd = ""
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

It just does not change it back to a 0 it leaves it at 1

Does any one have any ideas on what i am doing wrong?

Regards
Markus
 
What this code?
If IsNull(Card_Name) Then
Exit Sub
End If
Mybe Card_Name = null and this is why it exit the sub, and not getting to
the code.

any way, I suggest you step through the code.
1. Put the cursor on the first line of the code
2. press F9
3. run the form, when the code stop, step the code by pressing the F8 key.
4. see where the code goes, and the value of each variable


Markus said:
It does not work

Here is the exact code i use

Private Sub Card_Name_AfterUpdate()
Me![Card Name] = [Card Name]

[Card Price] = DLookup("[Card Price]", "Card Details", "[Card Name]=
Forms![Card Sales]![Card Name]")
If IsNull(Card_Name) Then
Exit Sub
End If

Me![Card Price] = [Card Price]

If IsNull([Forms]![Card Sales]![Card Name]) Or [Forms]![Card Sales]![Card
Name] = "" Then
[Forms]![Card Sales]![Qty] = 0
Else
[Forms]![Card Sales]![Qty] = 1
End If

End Sub

It will add the 1 but if you erase the combo box it does not set a 0 then

Ofer said:
Try this

If isnull([forms]![Sales]![Combo]) or [forms]![Sales]![Combo]="" then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
end if

Markus said:
Hallo

I am having the following problem with a combo box it linked to a table and
I can select a name from the table works fine then I have the statement
afterupdate to set a field called QTY to 1 but when I erase the combo box
again I want it to set the QTY field back to 0 it does not do that

I have tried the following

1)
if isnull([forms]![Sales]![Combo]) then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

2)
if [forms]![Sales]![Combo] = null then Even tryd = ""
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

It just does not change it back to a 0 it leaves it at 1

Does any one have any ideas on what i am doing wrong?

Regards
Markus
 
Thank you

i found the problem

Ofer said:
What this code?
If IsNull(Card_Name) Then
Exit Sub
End If
Mybe Card_Name = null and this is why it exit the sub, and not getting to
the code.

any way, I suggest you step through the code.
1. Put the cursor on the first line of the code
2. press F9
3. run the form, when the code stop, step the code by pressing the F8 key.
4. see where the code goes, and the value of each variable


Markus said:
It does not work

Here is the exact code i use

Private Sub Card_Name_AfterUpdate()
Me![Card Name] = [Card Name]

[Card Price] = DLookup("[Card Price]", "Card Details", "[Card Name]=
Forms![Card Sales]![Card Name]")
If IsNull(Card_Name) Then
Exit Sub
End If

Me![Card Price] = [Card Price]

If IsNull([Forms]![Card Sales]![Card Name]) Or [Forms]![Card Sales]![Card
Name] = "" Then
[Forms]![Card Sales]![Qty] = 0
Else
[Forms]![Card Sales]![Qty] = 1
End If

End Sub

It will add the 1 but if you erase the combo box it does not set a 0 then

Ofer said:
Try this

If isnull([forms]![Sales]![Combo]) or [forms]![Sales]![Combo]="" then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
end if

:

Hallo

I am having the following problem with a combo box it linked to a table and
I can select a name from the table works fine then I have the statement
afterupdate to set a field called QTY to 1 but when I erase the combo box
again I want it to set the QTY field back to 0 it does not do that

I have tried the following

1)
if isnull([forms]![Sales]![Combo]) then
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

2)
if [forms]![Sales]![Combo] = null then Even tryd = ""
[forms]![Sales]![QTY] = 0
Else
[forms]![Sales]![QTY] = 1
End if

It just does not change it back to a 0 it leaves it at 1

Does any one have any ideas on what i am doing wrong?

Regards
Markus
 
Back
Top