473,804 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set focus to sub form from main form

6 New Member
Hello,

I have a button on the main form and the follwing code when you click on it. Though the last record is the sub form (datasheet view) is shown, the focus remains on the button last_transactio n on the main form. I tried to get the focus on the sub form
Expand|Select|Wrap|Line Numbers
  1.  form_transaction.setfocus 
but i get an error 'the expression contains an invalid methode'. When I search for a solution everyone states that the above statement should work. But the focus remains on the button on the main form. What's wrong?
Thanks in advance
kind regards,
gerhard

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub last_Transaction_Click()
  3.  
  4. 'On Error GoTo Err_last_Transaction_Click
  5.  
  6. Dim frm As Form
  7.  
  8. Form_transaction.OrderBy = "transaction_number,transaction_date"
  9. Form_transaction.OrderByOn = True
  10.  
  11. 'Set reference to "subform"
  12. Set frm = Form_transaction.Form
  13.  
  14. 'Goto last record in subform
  15. If frm.RecordsetClone.RecordCount > 0 Then
  16.  frm.SelTop = frm.RecordsetClone.RecordCount
  17. End If
  18.  
  19. Exit_last_Transaction_Click:
  20.        Exit Sub
  21.  
  22. Err_last_Transaction_Click:
  23.     MsgBox Err.Description
  24.     Resume Exit_last_Transaction_Click
  25.  
  26. End Sub
  27.  
  28.  
Feb 24 '07 #1
6 2814
MMcCarthy
14,534 Recognized Expert Moderator MVP
The subform object does not necessarily have the same name as the form used as the subform. Open the main form in design view and click on (not in) the subform object. Open the properties window and under the other tab check the value in the Name property. This is the name of the subform object.

You are not refering to a form but to a subform object.

To refer to the main form use Me.

To refer to a control on the main form
Me.ControlName

To refer to a property of the main form
Me.PropertyName

To refer to a control on the subform
Me.SubformObjec tName.Form.Cont rolName

To refer to a property of the subform
Me.SubformObjec tName.Form.Prop ertyName

Mary
Feb 24 '07 #2
Gerhard Heemskerk
6 New Member
The subform object does not necessarily have the same name as the form used as the subform. Open the main form in design view and click on (not in) the subform object. Open the properties window and under the other tab check the value in the Name property. This is the name of the subform object.

You are not refering to a form but to a subform object.

To refer to the main form use Me.

To refer to a control on the main form
Me.ControlName

To refer to a property of the main form
Me.PropertyName

To refer to a control on the subform
Me.SubformObjec tName.Form.Cont rolName

To refer to a property of the subform
Me.SubformObjec tName.Form.Prop ertyName

Mary
Hello Mary,

It seems like the field client, within sub form transaction (dataview) got focus after clicking on the button last transaction in de main form. But that;s not the case. It is colored black. But still the button in the main form has the focus. Only clicking on client gives the focus on the sub form 'transaction'. The main form is called transaction.ent ry and the sub form transaction. The statement form_transactio n.setfocus or form_transactio n.klant stated in the sub of the button 'last transaction' still creates an error message. Please do you have a solution..
kind regards
gerhard
Feb 25 '07 #3
nico5038
3,080 Recognized Expert Specialist
Try:

form_transactio n.form.client.s etfocus

Nic;o)
Feb 25 '07 #4
Gerhard Heemskerk
6 New Member
Try:

form_transactio n.form.client.s etfocus

Nic;o)
Hello Nico,
Thanks for your answer but I got then following error:
By the application of object not defined error ..

kind regards
gerhard
Feb 26 '07 #5
nico5038
3,080 Recognized Expert Specialist
Make sure that the formname and controlname are correct!

Nic;o)
Feb 26 '07 #6
NeoPa
32,579 Recognized Expert Moderator MVP
Try setting the focus on the main form to its subform object first. Only then, set the focus to the item on the subform.
For help referencing the various controls and forms see (Referring to Items on a Sub-Form).
Feb 26 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

17
3868
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the main form when it's done, but I can't get it to do so if the user enters a value and presses Enter...
1
5060
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the focus Rectangle when your Selected Index changes ? 2) If there are no selected rows, can that focus rectangle be removed? 3) What other quirks exist in this simple example I might need to code for ?
2
5406
by: Sid Price | last post by:
Is there a way of stopping a form getting focus in VB.NET. The scenario I have is a main form and a form used for display only. There are no user controls on the display form and it does not ever need to have the focus. When the displays on the form are updated it appears to get the focus. I would like to prevent this because if the user operates any hot-keys (thinking the main form still has focus) these keys will fail. I have tried...
3
4252
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm application that need to "silently" use another app (called MapInfo) within itself - the intention is to use this app (which is quite sophisticated mapping application) and add some other extra functionality to it. We have a dll so we can run the...
3
3153
by: Johnny Jörgensen | last post by:
I've a form that opens a tool window. The problem is that when the tool window is opened, the main form itself passes focus to the toolwindow. What I want and need is a toolwindow that works like a control with tabstop=false, i.e. it doesn't get focus when the window is opened, but focus is retained at the main form. And when you click a button on the toolwindow, it processes the click event and returns focus to the main form. Is that...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.