Solved

setfocus in MS Access (VBA)

Posted on 2004-10-05
9
612 Views
Last Modified: 2012-06-27
I am finding it quite difficult to do a simple task in VBA within Access. Here is the code I am trying:

Me.ChangeFlag.Visible = False
Me.histdate.setfocus

The error I get on the first line is "you can't hide a control that has the focus". So, when I switch the lines around and try this:
Me.histdate.setfocus
Me.ChangeFlag.Visible = False

I get "Access can't move the focus to the control HistDate". HistDate is a text box. Any ideas?

Glenn
0
Comment
Question by:tkecowboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:snavebelac
ID: 12231170
Is Histdate disabled or locked ?  That would explain why the focus cannot move to it.

In your event to hide your first control, if you can move the focus to something else first - an enabled and unloacked control, it should work.

HTH

C
0
 

Author Comment

by:tkecowboy
ID: 12231290
well, I changed the code to look like this:

me.histdate.enabled = true
me.histdate.locked = false
Me.histdate.setfocus
Me.ChangeFlag.Visible = False

and I still get the error. In fact, I can't set the focus to any control on the form, which leads me to believe that there is sometihng in particular I must do within Access before setting focus on a control.
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12231458
Are the controls part of a locked or disabled tab control or options group ?

The code you have should work just fine.  Is HistDate definitely a textbox ?

C
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:tkecowboy
ID: 12231571
The controls look like they are on a standard form. I inherited this app, but I'm pretty sure there's nothing wierd going on. histdate is definitely a textbox.
0
 
LVL 6

Accepted Solution

by:
snavebelac earned 43 total points
ID: 12231713
I have created a simple form here and use dthe code an it works just fine.  I did manage to generate the same error by trying to move the focus to an option button.

Can you check the properties of the texbox (if you have not done so already) to make sure there is nothing strange going on there.

This seems a little odd to me...

C
0
 
LVL 41

Assisted Solution

by:shanesuebsahakarn
shanesuebsahakarn earned 41 total points
ID: 12232639
Are you absolutely sure that histdate is the name of the *textbox* and not the field within the textbox? Check the textbox's Name property in the properties window.
0
 

Assisted Solution

by:Mr_Ahmad
Mr_Ahmad earned 41 total points
ID: 12238049

Hi

Make sure the initial properties on the controls are set to visible = true, locked = false, the code will work afte that, else it will give you that error message.

Reg
Zaf
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question