Edit Command Macros/Visual Basic

L

lannalee

Hello,

How do I set a command button to open a new form and close the original form?

Here is the visual basic code that I am using to open the new form:

---------------------------------------
Private Sub Next_Degrees_Click()
On Error GoTo Err_Next_Degrees_Click


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form: Degrees/Education"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Next_Degrees_Click:
Exit Sub

Err_Next_Degrees_Click:
MsgBox Err.Description
Resume Exit_Next_Degrees_Click

End Sub
----------------------------------------

This is working like I need it to, except that I need the previous/original
form (Form: Personal Bigraphical) to close after the new form (Form:
Degrees/Education) is opened.

I am sure there must be a way to do it!
 
6

'69 Camaro

Hi.
How do I set a command button to open a new form and close the original
form?

After the line of code that opens the other form, use the Close method to
close the current form. Try:

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


lannalee said:
Hello,

How do I set a command button to open a new form and close the original
form?

Here is the visual basic code that I am using to open the new form:

---------------------------------------
Private Sub Next_Degrees_Click()
On Error GoTo Err_Next_Degrees_Click


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form: Degrees/Education"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Next_Degrees_Click:
Exit Sub

Err_Next_Degrees_Click:
MsgBox Err.Description
Resume Exit_Next_Degrees_Click

End Sub
----------------------------------------

This is working like I need it to, except that I need the
previous/original
form (Form: Personal Bigraphical) to close after the new form (Form:
Degrees/Education) is opened.

I am sure there must be a way to do it!
 
L

lannalee

Awesome! It worked, thanks for the help!

'69 Camaro said:
Hi.
How do I set a command button to open a new form and close the original
form?

After the line of code that opens the other form, use the Close method to
close the current form. Try:

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
6

'69 Camaro

You're welcome! Glad to help.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


lannalee said:
Awesome! It worked, thanks for the help!

'69 Camaro said:
Hi.
How do I set a command button to open a new form and close the original
form?

After the line of code that opens the other form, use the Close method to
close the current form. Try:

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

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