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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setfocus error !

Status
Not open for further replies.

Jonath

Technical User
Joined
Jul 13, 2007
Messages
27
Location
FR
Hi,

i'm working on a form with various unbound controls to deal with conversions; for instance the user chooses "M" or "F" but the record source in the table becomes "1" or "2".

When a user navigates through the records, i want the right information to be displayed on the form (M/F, not 1/2)

To do this I'm using Form_Current(); all works fine for 3 conversions until...i get 2110 error "can't activate control" when i add a 4th one. Well here's some code I use:


---

Private Sub FormCurrent()
...
Me.sexe.visible=true
Me.sexe.Setfocus
If Me.sexe.Text="1" Then
Me.listesexe.Setfocus
Me.Listesexe="M"
If Me.sexe.Text="2" Then
Me.listesexe.Setfocus
Me.Listesexe="F"
Me.sexe.visible=False
'this works fine

Me.telephone.visible=true
Me.Telephone.Setfocus
(...) 'same idea

Me.Nomdelavoie.visible=true
Me.Nomdelavoie.Setfocus 'Error is highlighted here
If Me.Nomdelavoie.Text Like "rue*" Then
(...)
End If


---

It is still a mystery to me...I deactivated Autocorrection of the control, used different names for the control and its source, tried "DoCmd.Gotocontrol" instead of "Setfocus"; the control is visible and enabled...nothing worked.


I also tried that code:
---
Private Sub FormCurrent()
...
Me.sexe.visible=true
Me.sexe.Setfocus
If Me.sexe.Text="1" Then
Me.listesexe.Setfocus
Me.Listesexe="M"
If Me.sexe.Text="2" Then
Me.listesexe.Setfocus
Me.Listesexe="F"
Me.sexe.visible=False
'this works fine

Me.Nomdelavoie.visible=true
Me.Nomdelavoie.Setfocus 'No error!

Me.telephone.visible=true
Me.Telephone.Setfocus
(...) 'same idea
---
This works but is incomplete (no If..Then). And strangely, this doesn't work anymore:

---
Private Sub FormCurrent()
...
Me.sexe.visible=true
Me.sexe.Setfocus
If Me.sexe.Text="1" Then
Me.listesexe.Setfocus
Me.Listesexe="M"
If Me.sexe.Text="2" Then
Me.listesexe.Setfocus
Me.Listesexe="F"
Me.sexe.visible=False
'this works fine

Me.Nomdelavoie.visible=true
Me.Nomdelavoie.Setfocus
If Me.Nomdelavoie.Text Like "rue*" Then
(...)
End If

Me.telephone.visible=true
Me.Telephone.Setfocus 'Error Here!!
(...) 'same idea

Me.Nomdelavoie.visible=true
Me.Nomdelavoie.Setfocus
---

I don't get it...can the If..Then be troublesome??!!

Any help would be appreciated; thanks in advance.

NB.: -version=Access2007
-i hope you understood it all...my english is perfectible :)
 
G'day Jonath

A few thoughts...

You don't need to use SetFocus.

Your IF..THEN construct is incorrect, it should be like:
Code:
If Me.sexe="1" Then
    Me.Listesexe="M"
ElseIf Me.sexe="2" Then
    Me.Listesexe="F"
End If

Have you considered using bound comboboxes to display what you need? For example, create a combo called 'cboSexe'. Set the following properties:

[tt]Control Source sexe
Row Source Type Value List
Row Source 1;"M";2;"F"
Column Count 2
Column Widths 0cm;1cm
Bound Column 1[/tt]

This produces a combo that has 2 columns and 2 rows:
[tt]1 M
2 F[/tt]

The bound column is 1, so the value that's saved to the control source 'sexe' will be 1 or 2.

The first column has a width of 0, so it won't display, and the user will see M or F.

This way you won't need to deal with unbound controls and conversions at all.


Max Hugen
Australia
 
sorry for my late response, max

Thanks a lot for your tips, it's indeed easier to use bound controls; i can't play with the code though :p

Jonath
Paris
 
Hi Jonath... if you use combo boxes as per my suggestion with cboSexe above (ie, using a 'Value List') then you won't need to use code. :-)

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top