I have multiple forms in access, How can I set focus on a "Form1" on load event of "Form2"?
I tried the below method, but it doesn't work. The focus is still on "Form2"
Private Sub Form_Load()
DoCmd.OpenForm "Form1"
Forms!Form1.SetFocus
End Sub
I have selected "Form2" in "Display Form:" option in "Access Options", I am opening "Form1" in "Form2" Load event and then trying to set focus to "Form1"
Thanks in advance
Changed :
I think the only solution is to open the form as a dialog :
DoCmd.OpenForm "Form1" ', , , , , acDialog
try it, it worked for me
Try this :
Private Sub Form_Activate()
DoCmd.OpenForm "Form1"
Forms!Form1.SetFocus
End Sub
Related
I open the form with:
DoCmd.OpenForm "Form", acNormal, , , acFormEdit, acWindowNormal
Forms Unload event:
Private Sub Form_Unload(Cancel As Integer)
If Len(Me.acntName.Value) = 0 Then
Msgbox "Account Name must be specified."
Cancel = True
Me.acntName.SetFocus
end if
End Sub
This returns me to the form, but does not give focus to the control. How do I do this?
In my MS-Access Database I Got a LoginForm, which checks If a User has Access to a specific form or Not.
My main, called "NavigationsFormular" has 4 Tabs
A normal User can access the 1st tab called "Bautagesbericht".
A ControlingUser can access the 2nd, 3d, 4th tab, but not the 1st!
The Login Form is a pop-up at start, I dont want to change it to a tab too,that would be ugly and not optimal.
After the Login succeeded, it loads up the Navigationform.
For the normal user its no problem, but for the controlling part it always says " No access " because it tried to open a tab he's not permitted to.
Thats the Code btw:
If Globals.UserAccess(Me.Name) = False Then
MsgBox " No access!"
DoCmd.Close acForm, Me.Name
End If
Now my idea was, that the Login Form open the form, which the user got permissions to by following code:
If Globals.UserAccess("frm_Räumstellenerfassung") = False Then
DoCmd.BrowseTo ObjectType:=acBrowseToForm, _
ObjectName:="frm_Taetigkeitseingabe_Büro", _
PathToSubformControl:="Navigationsformular.NavigationsUnterformular>frm_Taetigkeitseingabe_Büro.NavigationsUnterformular"
DoCmd.Close acForm, Me.Name
Else
DoCmd.OpenForm "Navigationsformular"
DoCmd.Close acForm, Me.Name
End If
End Sub
The Problem is that the Path is not right..
Hauptformular1 / MainFormular1 = "NavigationsFormular"
Unterformular1 / SubForm1 = "NavigationsUnterformular" (in German)
Formular1 = "frm_Taetigkeitseingabe_Büro"
Tried all combinations nothing helped.
BTW: A Button in my Naviagtion form with this Code is working. Apparently not when trying from an other form.
DoCmd.BrowseTo acBrowseToForm, "frm_Taetigkeitseingabe_Büro","Navigationsformular.NavigationsUnterformular"
ok I followed #June7 tipps. thanks for that. Here my solution:
Edited my form "frm_Räumstellenerfassung" ( Bautagesbericht) to
Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
If Globals.UserAccess("frm_Räumstellenerfassung") = False Then
DoCmd.BrowseTo acBrowseToForm, "frm_Taetigkeitseingabe_Büro", "Navigationsformular.NavigationsUnterformular"
End If
End Sub
So msg " No Access " is not popping up anymore and if the User has no rights to see this form, its browsing to the 2nd tab(Tätigkeitserfassung) without seeing any details of the 1st form.
My Login button just navigate to the navigationform
DoCmd.OpenForm "Navigationsformular"
DoCmd.Close acForm, Me.Name
I have working on forms, after i filled all the fields and Click on Save button, all fields have been saved but the text fields was not empty, all entered text still present, How do removed those text after hit on the save button
Go to a new record:
DoCmd.GoToRecord , , acNewRec
May be you would like to add the following in the click on save button event before "End Sub"
Me.TextboxName.Value = Null
Try this routine linked to a button you want to click to clear all textboxes in an unbound form:
Private Sub CleanAllFieldsButton_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then ctl = Null
Next
Set ctl = Nothing
End Sub
Private Sub Command47_Click()
On Error Resume Next
Me.Dirty = False 'Attempt to save the record
If Err.Number = 0 Then
'Only enter a new record, leaving other newly-added record accessible
DoCmd.GoToRecord , , acNewRec
Else MsgBox Err.DESCRIPTION, vbCritical, "Error"
End If
End Sub
Try this is in your save records click event.
I am having an issue with opening a zoom window in a sub form.
Basically, I have created a pop up window (form) which is suppose to appear upon double clicking in a memo field in a sub form to allow the user to be able to zoom in on the field and have additional ease upon entering long sentences.
I believe the problem is linked to the fact that the form which I am trying to create the zoom window is actually a sub form embedded in a form. My reasoning behind this is due to the fact that my code works perfectly well when i open the sub form alone and double click on the zoom in field..
Below is the code. The subform name is 'frmMasterListOfEventsDetails", the control / field to zoom in on in the sub form is called "notes2". The pop up window (subform) is named "frmZoom" and its control (text box) where the information is to be entered is called "txtZoom".
I would appreciate any help you may have.
Thank you
Private Sub Notes2_DblClick(Cancel As Integer)
If Me.AllowEdits = False Then
Messaggi.MessaggioExclamation
Else
Me.Refresh
DoCmd.OpenForm "frmzoom", acNormal, , , , acDialog
End If
End Sub
Private Sub Form_Close()
Forms("frmMasterListOfEventsDetails")!Notes2 = Me.txtZoom
Forms("frmMasterListOfEventsDetails").Refresh
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.txtZoom = Forms("frmMasterListOfEventsDetails")!Notes2
End Sub
I believe the problem is linked to the fact that the form which I am trying to create the zoom window is actually a sub form embedded in a form
I believe you are correct. Since frmMasterListOfEventsDetails is a subform,
Forms("frmMasterListOfEventsDetails")
will not find it. You need to go through the main form:
Forms("parentFormName").Form.frmMasterListOfEventsDetails.Form.Notes2 = Me.txtZoom
I'm late but you can just use the SHIFT+F2 to get a zoom a any textbox in Microsoft Access
Probably, a better aproach (since you can reuse it on other forms) is this:
Private Sub Notes2_DblClick(Cancel As Integer)
If Me.AllowEdits = False Then
Messaggi.MessaggioExclamation
Else
Me.Refresh
DoCmd.OpenForm "frmzoom", acNormal, , , , acDialog, Me!Notes2
if IsOpened("frmzoom") then
Me!Notes2 = Forms!frmzoom!txtZoom
DoCmd.Close acForm, "frmzoom"
end if
End If
End Sub
'Independent module
Public Function IsOpened (stNameOfForm as string) As Boolean
Dim i As Integer
For i = 0 To Forms.count - 1
If Forms(i).Name = stNameOfForm Then
IsOpened = True
Exit Function
End If
Next
End Function
'frmzoom module
Private Sub Form_Open(Cancel As Integer)
Me.txtZoom = Me.OpenArgs
End Sub
Private Sub Btn_OK_Click() 'frmzoom Button OK
Me.Visible = False
End Sub
Private Sub Btn_Cancel_Click() 'frmzoom Button Cancel
DoCmd.Close
End Sub
As you can see, the zoom dialog receives the data from the form that calls it and then collects the information directly depending on the status (open / closed); thus the Zoom dialog does not need to know the name of any control and can be used by any form.
When a button is pressed I want to open a form at a specific tab.
on click event I have:
DoCmd.OpenForm "MAIN_USER_FORM", acNormal, , "App_Ref = " & Me.App_Ref, , , "PRB"
On the open event of the form I have:
If Me.OpenArgs = "PRB" Then
Me.PRB_Validation.SetFocus
End If
PRB_Validation is the name of the tab in the MAIN_USER_FORM I wish to open.
I've searched forms, I just can't get it to work any help would be great.
Thanks in advance.
All you need is to check the OpenArgs in the form's OnLoad event, and set the TabCtontrol's value to the index of the page you want to show, like this:
Private Sub Form_Load()
If OpenArgs = "PRB" Then
TabCtl0.Value = PagePRB.PageIndex
End If
End Sub
I made an example accdb to show the complete setup.
In case if anyone is looking for code where you have a button on another form and want to open Main form from that and also take user to a particular Tab.
Private Sub YourButton_Click()
On Error GoTo Err_YourButton_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "YourFormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![YourFormName]!YourPage.SetFocus
Exit_YourButton_Click:
Exit Sub
Err_YourButton_Click:
MsgBox Err.Description
Resume Exit_YourButton_Click
End Sub