Working in with Pages on Tab

A

Ayo

I want to know if this is possible and if so, how? I have a form with a Tab
control with 3 Pages on it. I want to know if it is possible to set it up
such that when the form is open, I can open the Tab control Page to any one
of the thress pages.
Take for instance, when the form is Loaded but I want it to open to Page 2
or Page 3 of the Tab control. How do I do that?
 
A

Allen Browne

I take it you want to programmatically open the form, and then choose Page 2
of the tab control?

The code would be like this:
DoCmd.OpenForm "Form1"
With Forms("Form1")
.MyTab = MyPage2.PageIndex
End With

Substitute:
- your form name for Form1
- your tab contorl name for MyTab
- your page control name for MyPage2.
 
A

Ayo

Thank you so much Allen.

Allen Browne said:
I take it you want to programmatically open the form, and then choose Page 2
of the tab control?

The code would be like this:
DoCmd.OpenForm "Form1"
With Forms("Form1")
.MyTab = MyPage2.PageIndex
End With

Substitute:
- your form name for Form1
- your tab contorl name for MyTab
- your page control name for MyPage2.
 
A

Ayo

I tried the suggestion you made but I am still getting an "Object Required"
error. Below is the full code. Maybe you can tell me what I am doing wrong.
Thanks Allen.

Function OpenSiteRecordForEditing()

On Error GoTo Error_OpenSiteRecordForEditing

DoCmd.Minimize

DoCmd.OpenForm "frmSiteConstruction_Information", datamode:=acFormEdit, _
wherecondition:="[SITE NUMBER]='" & Me.[SITE NUMBER] & "'",
OpenArgs:=Me.Name
With Forms("frmSiteConstruction_Information")
.TabCtl90 = PgOtherDates.PageIndex(1)
End With

Exit_OpenSiteRecordForEditing:
Exit Function

Error_OpenSiteRecordForEditing:
MsgBox Err & ": " & Err.Description
OpenSiteRecordForEditing = False
Resume Exit_OpenSiteRecordForEditing
End Function
 
D

Douglas J. Steele

PageIndex isn't an array or collection. It's an integer value between 0 and
one less than the value of Pages.Count for the tab control.

Try changing

.TabCtl90 = PgOtherDates.PageIndex(1)

to

.TabCtl90 = PgOtherDates.PageIndex


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ayo said:
I tried the suggestion you made but I am still getting an "Object Required"
error. Below is the full code. Maybe you can tell me what I am doing
wrong.
Thanks Allen.

Function OpenSiteRecordForEditing()

On Error GoTo Error_OpenSiteRecordForEditing

DoCmd.Minimize

DoCmd.OpenForm "frmSiteConstruction_Information", datamode:=acFormEdit,
_
wherecondition:="[SITE NUMBER]='" & Me.[SITE NUMBER] & "'",
OpenArgs:=Me.Name
With Forms("frmSiteConstruction_Information")

Exit_OpenSiteRecordForEditing:
Exit Function

Error_OpenSiteRecordForEditing:
MsgBox Err & ": " & Err.Description
OpenSiteRecordForEditing = False
Resume Exit_OpenSiteRecordForEditing
End Function


Allen Browne said:
I take it you want to programmatically open the form, and then choose
Page 2
of the tab control?

The code would be like this:
DoCmd.OpenForm "Form1"
With Forms("Form1")
.MyTab = MyPage2.PageIndex
End With

Substitute:
- your form name for Form1
- your tab contorl name for MyTab
- your page control name for MyPage2.
 
A

Ayo

I am still getting the same error message and it is not working.

Douglas J. Steele said:
PageIndex isn't an array or collection. It's an integer value between 0 and
one less than the value of Pages.Count for the tab control.

Try changing

.TabCtl90 = PgOtherDates.PageIndex(1)

to

.TabCtl90 = PgOtherDates.PageIndex


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ayo said:
I tried the suggestion you made but I am still getting an "Object Required"
error. Below is the full code. Maybe you can tell me what I am doing
wrong.
Thanks Allen.

Function OpenSiteRecordForEditing()

On Error GoTo Error_OpenSiteRecordForEditing

DoCmd.Minimize

DoCmd.OpenForm "frmSiteConstruction_Information", datamode:=acFormEdit,
_
wherecondition:="[SITE NUMBER]='" & Me.[SITE NUMBER] & "'",
OpenArgs:=Me.Name
With Forms("frmSiteConstruction_Information")

Exit_OpenSiteRecordForEditing:
Exit Function

Error_OpenSiteRecordForEditing:
MsgBox Err & ": " & Err.Description
OpenSiteRecordForEditing = False
Resume Exit_OpenSiteRecordForEditing
End Function


Allen Browne said:
I take it you want to programmatically open the form, and then choose
Page 2
of the tab control?

The code would be like this:
DoCmd.OpenForm "Form1"
With Forms("Form1")
.MyTab = MyPage2.PageIndex
End With

Substitute:
- your form name for Form1
- your tab contorl name for MyTab
- your page control name for MyPage2.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

I want to know if this is possible and if so, how? I have a form with a
Tab
control with 3 Pages on it. I want to know if it is possible to set it
up
such that when the form is open, I can open the Tab control Page to any
one
of the thress pages.
Take for instance, when the form is Loaded but I want it to open to
Page 2
or Page 3 of the Tab control. How do I do that?
 
D

Douglas J. Steele

Okay, both Allen and I missed a period, which is why you're getting the
error message. Since PgOtherDates is the name of a Page control on the form,
it should have been:

..TabCtl90 = .PgOtherDates.PageIndex

However, it turns out Allen was incorrect that that would do what you want.

Instead, use

DoCmd.OpenForm "frmSiteConstruction_Information", datamode:=acFormEdit, _
wherecondition:="[SITE NUMBER]='" & Me.[SITE NUMBER] & "'", _
OpenArgs:=Me.Name
With Forms("frmSiteConstruction_Information")
.PgOtherDates.SetFocus
End With

Sorry about that.

Let me add, though, that the reason you got that particular error message is
because you haven't told Access to require that all variables be declared.
Look at the top of your module. It should have the line

Option Explicit

there (either the 1st or 2nd line)

If you had that line there, you would have got a "Variable not defined"
error instead, because Access would have assumed PgOtherDates was a
variable.

Go into the VB Editor and select Tools | Options. Look on the Editor tab.
The checkbox "Require variable declaration" should be checked. That will
ensure that Option Explicit gets added to all future modules.
(Unfortunately, you'll have to go and add it manually to all the existing
modules). While it may be a pain having to correct any oversights in your
code, having that option set will ultimately save you hours of time.
 
A

Ayo

Thank you some much guys. You've both been a great help.

Douglas J. Steele said:
Okay, both Allen and I missed a period, which is why you're getting the
error message. Since PgOtherDates is the name of a Page control on the form,
it should have been:

..TabCtl90 = .PgOtherDates.PageIndex

However, it turns out Allen was incorrect that that would do what you want.

Instead, use

DoCmd.OpenForm "frmSiteConstruction_Information", datamode:=acFormEdit, _
wherecondition:="[SITE NUMBER]='" & Me.[SITE NUMBER] & "'", _
OpenArgs:=Me.Name
With Forms("frmSiteConstruction_Information")
.PgOtherDates.SetFocus
End With

Sorry about that.

Let me add, though, that the reason you got that particular error message is
because you haven't told Access to require that all variables be declared.
Look at the top of your module. It should have the line

Option Explicit

there (either the 1st or 2nd line)

If you had that line there, you would have got a "Variable not defined"
error instead, because Access would have assumed PgOtherDates was a
variable.

Go into the VB Editor and select Tools | Options. Look on the Editor tab.
The checkbox "Require variable declaration" should be checked. That will
ensure that Option Explicit gets added to all future modules.
(Unfortunately, you'll have to go and add it manually to all the existing
modules). While it may be a pain having to correct any oversights in your
code, having that option set will ultimately save you hours of time.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ayo said:
I am still getting the same error message and it is not working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top