I need to open a specific page on a TabControl, which is on a form that has two TabControls - vba

I have a Form named frmSearchAirport
I have two tab controls on the form named TabControl1 and TabControl2.
Each tab control has five pages.
On another Form i have command buttons.
I want to use each command button to open a page on a TabControl and to make the inactive TabControl invisible
I wrote this code for one of the command buttons so that it would open the first page on TabControl2 and and make TabControl1 invisible but i get an error message saying the action or method requires a form name argument
DoCmd.OpenForm FormName:=frmSearchAirport, View:=acNormal, OpenArgs:=0
Forms![frmSearchAirport].TabControl1.Visible = False
and this code for the On Load event of the Form named frmSearchAirport
Private Sub Form_Load()
If IsNull(Me.OpenArgs) = False Then
Me.TabControl1 = Me.OpenArgs
Me.TabControl2 = Me.OpenArgs
End If
End Sub
Can anyone help with this.
Thank you
Edit 1:
Ive since changed the code to this and im getting an Application Defined or Object Defined error
DoCmd.OpenForm FormName:="frmSearchDublinAirport", View:=acNormal,OpenArgs:=0
Forms![frmSearchDublinAirport].Form.TabControl1.Visible = False
Edit 2:
ive changed the code to this. The form is actually opening on the correct page but the other TabControl is still visible and the pop up error message appears saying Application Defined or Object Defined error
DoCmd.OpenForm FormName:="frmSearchAirport", View:=acNormal, OpenArgs:=0
Forms![frmSearchAirport].TabControl1.Visible = False
Edit 3:
This code is working. the problem was I named the TAbControl incorrectly. I used TabControl1 instead of TabControlOne
DoCmd.OpenForm FormName:="frmSearchAirport", View:=acNormal, OpenArgs:=0
Forms![frmSearchAirport].TabControlOne.Visible = False

The FormName parameter of DoCmd.OpenForm needs a string - the form name.
So you probably need:
DoCmd.OpenForm FormName:="frmSearchAirport", View:=acNormal, OpenArgs:=0

Related

Show/Hide FileExplorer in Access Form

I've been trying to use a combobox to show/hide a PDF viewer that I've added into a MS Access form.
When I use the form_current event, then the form only updates when I move between the data entries. When I use the afterupdate event, the same code does nothing at all.
Does anyone have a fix? The code I have used is below, which I have tried both the AfterUpdate event for the Browser and the Form_Current event for the whole form
Private Sub PDFT900_AfterUpdate() / Private Sub Form_Current()
Dim ESNComb As String
ESNComb = Me.ESNCombo.Column(1)
If ESNComb Like "9????" Then
Me.PDFT900.Visible = True
Else
Me.PDFT900.Visible = False
End If
End Sub
In the code below, I'm hiding and showing the Adobe PDF Reader ActiveX control named, "AcroPDF0". Since the Like operator returns true on an expression match and false on a mismatch or no match, it serves as a simple boolean switch for the visible property. I've used the (*) wild card instead of (?). It works {shrug}. See demonstration images below.
Private Sub ESNCombo_AfterUpdate()
'AcroPDF0.Visible = ESNCombo.Text Like "P*"
AcroPDF0.Visible = ESNCombo.Column(0) Like "P*"
AcroPDF0.src = acroPDFOSrc
End Sub
ComboBox List Items
"File Browser" Selected in ComboBox
Toggled ComboBox back to "PDFT900"

Subform OnCurrent Error on Main Form Open

I have the following code on a subform's on current, but it errors on open of the main form:
If IsNull([Forms]![frmMContacts]!ID) Then
With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
.Enabled = False
End With
Else
With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
.Enabled = True
End With
If Me.NewRecord Then
Me.txtCurrRec = "New Contact Role Record"
Else
Me.txtCurrRec = CStr(Me.CurrentRecord) & " of " & _
DCount("ID", "tblContactPeople", "FKClient = " & Me.Parent.CM_CID) & " Contact Roles"
End If
End If
The point of it is, simply to update a text box in the form's footer, to provide a count of records for the sub form. The issue is that when a user opens the main (parent) form, from the main menu, the main record has no record, and the sub form is still loading. In reality, I'm hiding the detail of the main form, and hence this sub form is hidden. The user has to hit 1 of 2 buttons in the main form header. Either find a record (pop-up form) or start a new one (another pop-up form).
When I try to open this main form, I get the error "run-time error '2465' application-defined or object-defined error".
I'm not sure how to trap this and just either make the sub-form disabled or prevent this on-current code form firing, until the parent has a record.
Thanks for any help!

Getting a Modal pop form to show up in Access

i'm trying to use the following code to open a Form using VBA
Private Sub cmdEdit_Click()
Dim d As New Form_EditNote
d.txtDate.Value = EntryDate.Value
d.txtNote.Value = Note.Value
d.Visible = True
End Sub
the form opens but only for a split second .. then goes away... any ideas?
You are declaring your variable d, assigning it to your form, you make the form visible, then your function is over and all your local variables are destroyed. Your form is one of these local variables. You need to use DoCmd.OpenForm EditNote. That will keep it open
To make it modal, either set the modal porperty to true at design time if you always want it to be modal. Or in DoCmd.OpenForm set the WindowMode to acDialog

VBA - The Form Class has no the show method

I want create one form from another. But the Form class has no the Show method, which described at http://msdn.microsoft.com/en-us/library/office/gg251540.aspx
It's code in Form_Main:
Private Sub btnTemp_Click()
Dim frmOpt As Form_Option
Set frmOpt = New Form_Option
frmOpt.Show vbModal
End Sub
But I received the "Compile error: Method or data member not found".
Where I made mistake?
Thanks
(VBA version 6.5; Access 2007)
=====
Sorry for my previous comment: right now I see that comment isn't obvious.
I don't have subForm on my mainForm.
I have two simple form: Form_Main and Form_Option. And I want to be the next logic:
Form_Main has button "btnOption"
Click on "btnOption". The Form_Option is opening
I change options on Form_Option
And click the btnSave button on Form_Option, and the next idea is executing:
Form_Main.TimerInterval = CLng(Form_Option.edtTimerInterval.Value)
At the moment I made it simple. And that is enough for me.
I write so:
Private Sub btnOptions_Click()
' After changing options, refresh timer interval of main form
DoCmd.OpenForm "Options", , , , , acDialog
Me.TimerInterval = 1000 * CLng(MOptions.loadOption("fPeriodVerifyNoticeInterval"))
End Sub
Where fPeriodVerifyNoticeInterval is parameter that stored in the options table.
And the Options Form changes the "fPeriodVerifyNoticeInterval" parameters at saving.
My problem is solved, Thanks
The "mistake" is that Show isn't a valid Method for Access Forms. The link you provided is for UserForms which are forms made in VBA.
If you want to create a new form that way what you want is something like this:
frmOpt.Modal = true
frmOpt.Visible = true
Though what I would recommend is doing this instead:
DoCmd.OpenForm "Option", , , , , acDialog which will open the Option form as a dialog.
Caution: If you create your form using New even though you set it as modal it will not halt the progress of VBA code. This means that your variable will go out of scope as soon as the code finishes. If you want your form to remain open, you will need to set it as static within the sub or declare it outside the sub like this:
static frmOpt As Form_Option
or outside the sub private frmOpt = Form_Option or public frmOpt = Form_Option

VB.Net WebBrowser Navigate Only Working Once

Hoping someone can help me with this. I have two separate but related Forms, one of which contains a WebBrowser control. The user fills out some information on Form 1 and clicks a button with the following code:
If Form2Shown = False Then
Dim memoscreen As New Form2
Form2Ref = memoscreen
memoscreen.show()
Form2Shown = True
memoscreen.TopMost = OptionOnTop
Else
Dim memoscreen As Form2
memoscreen = Form2Ref
memoscreen.TopMost = OptionOnTop
memoscreen.QuickRefresh()
End If
The QuickRefresh sub in Form2 is the method that navigates. It is called both when the form is loaded as well as manually in the code above:
Public Sub QuickRefresh()
Dim HM As Form1
HM = Form1Ref
Me.Text = "retrieving information..."
Me.AxWebBrowser1.Navigate("SomeValidURL")
HM.Focus()
HM.SetHugoFocus()
End Sub
The problem I'm having is that the first time QuickRefresh is called (i.e. when Form2 is loaded) the navigation is successful and the page displays fine. If I then click the button on Form1 again, the page does not change. The Text attribute and window focus does change however, so I know the method is firing.
Some things I've tried/checked:
AllowNavigation is set to True on the WebBrowser control
Have tried looping while the browser is busy while calling Application.DoEvents()
Any suggestions would be appreciated. Thanks.
From your "Internet Options dialog > General Tab > Settings Button > Check for newer version of stored page" change that option to *Every Time I visit the webpage". That setting impacts how the webbrowser control deals with the refreshing.
Use the method refresh.
browser.Navigate("http://www.google.com") : browser.Refresh()