Modules & VBA :: Setting Focus To Non Default Instance Of A Form
Mar 21, 2014
How to set focus to a non Default instance of a form.
Environment
A2007 ADP Project
Document Window Option - Tabbed Documents
MS SQL 2012 Express DB
Windows 7 64 Bit
I using Allen Browne's method to open more that one version of form, storing each form object in a collection declared in a module. No problem there.
Now I'm trying to add a command button on an form to set focus to one of these non-default instances already open.
The form I am trying to set focus to has a the following related properties
Default View: Split Form
Pop-up: No
Modal: No
The form that has the command button on it is of the same type.
Here is the code I've tried:
'Code on Calling Form
Private Sub cmdProjectList_Click()
Dim FunctionResult As Boolean
If AppForms.GoToForm("ProjectList") = False Then
AppForms.Load_ProjectList
[Code] .....
The code compiles and executes with seemingly no problems. It finds the form loaded, then cycles though and finds the form in Forms but the SetFocus call seems to do nothing. When I run the code against a defualt instance ( one not opened using Allen Browne's method) it works fine and sets focus to it as expected.
I am new to Access and to the forum. I made a check printing system
table name = 'burgan' form name = 'burgan cheque' Fields = 'PV' and 'cheque' and 'Beneficiary'
I have inserted a button (Command31).The function I would like to add on clicking the button
1. it should chose the highest value in both fields (PV and cheque) 2. Create new record 3. Increment it by 1 (both fields 'PV' and 'cheque') 4. the focus should stand on 'Beneficiary' field.
I'm populating a report with a query which pulls criteria from a form. When the 'run' button is pressed it opens the report, running the query, to filter the data. What i'm attempting (and it works if there is data present).
The data is text, which is a filename, which populates an image control. Most of my records have an image present but for the ones that don't I think I need to turn the image control's picture property to 'blank'.
I'm just now encountering problems with the records with no pictures so when i came up with this it worked with my tests which at that time only had images present....
I have two problems.
1) When I run the code as below i get Run-Time Error 2185; you can't reference a property or method for a control unless the control has the focus.
2) when i try to set the focus on the picture control in the report to see if there is text/value present i get runtime error 2478; database doesn't allow you to use this method in the current view.
I assume this is talking about me opening the report in acViewPreview mode but i thought i needed to do this so the images are displayed in the image control.
Code: Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) Dim strDBPath As String Dim strRelativePath As String Dim strPath As String 'rptOriginalOwnerCategoryItem!Picture.Text.SetFocus [B]Me!Picture.SetFocus[B] 'Test to see if the record has a relative path stored
I have a Main Form with a tab control. On each of the six tabs is a SubForm that takes up the entire tab. So basically I have a tabbed interface for my forms, just with a bit more control over the layout than if I just opened the forms separately in the Access window.
Anyway, on one of those subforms is a button. When you click it, it opens a separate form in a pop-up window, which is used to find a specific record. Once that record is found, you can click another button, and the idea is that this pop-up window closes, and you return to the underlying form, which jumps to the record you selected.
So far so good. Now, if I am working on my program in Access, and I open that subform's source form separately in its own tab, click the icon to open the record finding form, find a record, and then click the button to load that record, the following code runs, and it runs flawlessly - closing the pop-up window, and passing the information back to the main form which displays the proper record:
Quote:
Private Sub ViewRecord_Click() Dim RecordID As Integer RecordID = Me.ID DoCmd.OpenForm "CDLExam", , , "ID = " & RecordID DoCmd.Close acForm, "CDLExamCONT", acSaveNo End Sub
Where my program falls apart is that, in actual use, this form is not open on its own. It's open as a subform on one tab of a tab control on a Main Form. So the third line of code falls apart. Access thinks I want to open CDLExam separately, but it can't because it's already open in the subform, so instead I just end up back at the main window like I want, but the form fails to move to the proper record. Basically, line 3 just doesn't do anything.
How can I make this work? I tried replacing "CDLExam" with the name of the main window, but then it tries to move to the record in the main window, which throws an error as the main window doesn't even have a record source attached to it.
how to refer to the SUBFORM which has CDLExam open, and tell THAT to move to the proper record.
I have a button in a form that brings the user to a table to add a new record. I want the feild of "dates" to be automaticlly populated with a value that is 7 days after the previous date in the field. the code i have currently is
Code: Private Sub Command14_Click() DoCmd.OpenTable "Cincinnati Time Sheet", acViewNormal DoCmd.GoToRecord , , acNewRec End Sub
When I right click a row on the data sheet side of a split form an select "New Record" I want the curser to go to the first field on the single record side. I've placed this in the OnCurrent but it did no good.
Code:
If Me.NewRecord Then Me!Descrfiption.SetFocus. End If
Any way to set the focus to the single form Side of a split form?
I am having an issue setting an instantiated forms' control. I am having RemDate ("Date") and RemTime ("Time") TextBox; so far the date textbox shows 1/1/1988 12:00 AM (the visible value is the time only) and the Time textbox doesn't show anything.
Code: Set frm = New Form_ReminderAssigneesFrm frm.RecordSource = "Select * from ReminderAssignees Where RemID = " & Parent.RemID frm.RemID.DefaultValue = Parent.RemID With SetRS(frm.RecordSource) If Not .EOF Then frm.RemDate.DefaultValue = FormatDateTime(.Fields("RemDate"), vbShortDate)
On a form i have a text box which holds the date that a file batch was taken to be processed. Each file holds the date of when the batch it originated from was taken. At the moment for ease of use the 'Default Value' of the text box is set to the batch's date.
I want to set it up so i can change the default value of the cell, so that when a new batch is to be processed the new date becomes the default value.
I am invisaging a button which brings up another form with a text box into which the new date can be put. when the form is saved and closed, the date recieved cell on the master form assumes the new default value.
my code does the following, user selects excel file, opens it, renames sheets, basically needs first sheet to be sheet1. rest don't matter Changes the formats in column a to number and 15dp, saves the file as .xls and then links the file to the database.
Code: Private Sub Command288_Click() Dim s As String Dim i As Long
I have a combo box field on a Student Details form that displays the Student's class number. For a new record, I am able to set the default value in the control's Default Value property with a literal in quotes (ie., ="2015-1"). But I want to set the default value from a query field. However, when I specify the query field in an expression ((=[Current Class]![Class Number]), "#Name?" appears in the field when initiating a new record on the form.
The control source for is the field in the Students table ([Students.[Class Number]).
The Row Source is a query of the Class table.
How can I set the control's default to the Class Number value in the Current Class query?
I am using the method from allen browne [URL] .... to open a form and add it to a collection and when removing it it closes. actually, usually it does work so but i have now a form which does not close until i am hitting the reset button in VBE , is there something i could check why it's not functioning as desired ?
Just to add, this form has a subForm as well (might be the cause ?)
how would i go about setting focus on a tab control? i have a tab control on a form with 6 tab pages. i am on page 4 ( bank ) and i have a button to add a bank account. this opens up the add form and i add the account. i then requery the form and the tab goes back to page 1. how do i set the focus back to the previous opened tab?
i have a tabular form, which on its after update event, i requery the form, and it works fine. However, my only problem is that after the requery occurs, the focus moves to the first field of the first record. Is there a way in which after the requery, the focus will be set at the end, in that blank record, where to insert a new record ?
I am having trouble setting the focus on my forms... I have a parent form with two labels that are coded like this.
Private Sub Advisory Messages_Click() Me![ Advisory Messages].Visible = _ Not Me![Advisory Messages].Visible End Sub
[code]...
I have the visible property set to no on the subform allowing the user to toggle the visibility when the label is clicked. The problem though is when I click inside the subform to use the scroll bar to view records, it transfers the focus to the subform making it almost impossible to close by clicking the label again because the label is on the parent form. I found the "me.parent.setfocus" command and a few other set focus commands but I don't know what I should be applying the command to in order to make it work.
it is possible to be able to scroll through a List Box with just a mouse over? Or, do you need to set focus on the ListBox before being able to scroll?
I have a form with a tab control on it. The input for respective fields are placed inside the tab control, and I have the "Confirm" button placed outside, on the main form. Now I wanted to be able to navigate my focus from a control from inside to tab control, out to the Confirm button on the form, to allow smooth flowing data entry.
However, it seems like Access separates the tab indexes for the controls in the tab control and outside on the main form, so setting tab index does not work. I tried using the code ON LOST FOCUS and SET FOCUS;
Private Sub txtPurchaseNote_LostFocus() Forms![frm Imported]![cmdConfirmPurchase].SetFocus End Sub
But then a dialog box appears:
Run-time error '2110' Microsoft access can't move focus to the control cmdConfirmPurchase
Hi, I'm trying to set a default value to field in a form. The field relates to Table 1 and I need a value from Table 2 as Default! I've tried entering an SQL query: Select Max(ID) From.... ; But it doesn't work! Maybe It's just a question of syntax?? Thanx for your help.
I am trying to set a default value in a date field. I would like for the default value for this field to be the date thirteen days from the last date entered. How would I go about doing that... Any help would be greatly apprecated.
I have two problems excel instance does not close at the end and two when I try to do the looking using text it works but soon as I try using date/time it returns nothing.
Code: Private Sub Command84_Click() Dim objExcel As Excel.Application On Error Resume Next
I just want to run a series of DoCmd.TransferSpreadsheet commands to export several queries to one Excel Workbook with seperate sheet names for each query.
However my problem is I want this to be a new instance of Excel that the user will then SaveAs after it is complete. I don't want to save it to a specific path first because the Db is on a shared drive and My Documents will have a different path for each user based on their user name. (corporate environment)
There must be some way to just have it open a new workbook without saving isn't there??
I am not sure if I am even able to do this, but I am wondering how to set the default value for a field when creating a database using SQL. I am doing everything with coldfusion and I havn't been able to figure out what code needs to be there. I have tried everything I can think of. Any help would be appreciated.