Listbox value copies to two fields?

  • Thread starter Thread starter DubboPete
  • Start date Start date
D

DubboPete

Hi all,

I have a listbox which includes four or more teams, each team is numbered 1
thru 4 or more.

When I click my listbox team, I would like [teamA] to be updated to that
value, and on clicking the listbox a second time, [teamB] to be updated to
the second value.


My code however updates BOTH boxes simultaneously. Can someone point out
where it's going wrong please?

Private Sub List6_Click()

If Not (CInt(Me.[TeamA] = 0)) Then
'if Team A is already selected then
Me.[TeamB] = Me.List6
Else
'update Team A
Me.[TeamA] = Me.List6
End If


thanks in anticipation

DubboPete
End Sub
 
DubboPete said:
Hi all,

I have a listbox which includes four or more teams, each team is numbered 1
thru 4 or more.

When I click my listbox team, I would like [teamA] to be updated to that
value, and on clicking the listbox a second time, [teamB] to be updated to
the second value.


My code however updates BOTH boxes simultaneously. Can someone point out
where it's going wrong please?

Private Sub List6_Click()

If Not (CInt(Me.[TeamA] = 0)) Then
'if Team A is already selected then
Me.[TeamB] = Me.List6
Else
'update Team A
Me.[TeamA] = Me.List6
End If


thanks in anticipation

DubboPete
End Sub


Check to make sure that the two controls have different names.

Check to make sure the two controls are bound to different fields in the
table.


Also, the CInt() doesn't have any effect because (Me.[TeamA] = 0)
evaluates to True (-1) or False (0). Try this:

Private Sub List6_Click()

If Nz(Me.[TeamA],0) > 0 Then
'if Team A is already selected then
Me.[TeamB] = Me.List6
' remove later
msgbox "Team B updated"
Else
'update Team A
Me.[TeamA] = Me.List6
' remove later
msgbox "Team A updated"
End If
End Sub
 
Thanks Steve

Works great. Now I can move on to selecting referees who aren't coaching
one of those teams simultaneously!

watch this space for more guidance!

DubboPete
 
Hi Steve et al,

Values update correctly, but the two linked 'DLookup' text boxes now don't
update.
However, if I flick to design view, and then back to Form View, they are
visibly updated...

any clues?

Pete

SteveS said:
DubboPete said:
Hi all,

I have a listbox which includes four or more teams, each team is numbered
1 thru 4 or more.

When I click my listbox team, I would like [teamA] to be updated to that
value, and on clicking the listbox a second time, [teamB] to be updated
to the second value.


My code however updates BOTH boxes simultaneously. Can someone point
out where it's going wrong please?

Private Sub List6_Click()

If Not (CInt(Me.[TeamA] = 0)) Then
'if Team A is already selected then
Me.[TeamB] = Me.List6
Else
'update Team A
Me.[TeamA] = Me.List6
End If


thanks in anticipation

DubboPete
End Sub


Check to make sure that the two controls have different names.

Check to make sure the two controls are bound to different fields in the
table.


Also, the CInt() doesn't have any effect because (Me.[TeamA] = 0)
evaluates to True (-1) or False (0). Try this:

Private Sub List6_Click()

If Nz(Me.[TeamA],0) > 0 Then
'if Team A is already selected then
Me.[TeamB] = Me.List6
' remove later
msgbox "Team B updated"
Else
'update Team A
Me.[TeamA] = Me.List6
' remove later
msgbox "Team A updated"
End If
End Sub
 
sorry, should have been more specific

[teamA] = 2
TeamA value of 2 = Strikers (team name)

When [teamA] is updated using Steve's code, [teamA] shows correct value (2).
The (linked to [teamA]) Dlookup text field [team name] doesn't however
update to current selection (Strikers) ... how do I refresh it? I've
tried heaps of places to refresh the box, but to no avail!

cheers

Pete
 
Forget my last, I had the wrong values in DLookup syntax.... now it works!
d'oh!

thread closed..... and sorry

The Goat Herder
 
DubboPete said:
Forget my last, I had the wrong values in DLookup syntax.... now it works!
d'oh!

thread closed..... and sorry

The Goat Herder

Whew, you tired me out. <bg>

Glad it is finally working....
 
Back
Top