Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open New / Close Old 1

Status
Not open for further replies.

troix

Technical User
Jan 20, 2004
46
US
I am trying to create a button that will OPEN "CAREPLAN" and CLOSE "PSAFILES".

PSA Files has a data field called "PSAID" and is an autonumber and must auto fill in "CAREPLAN" as "PSAID"

I had something like the below but it's not working for whatever reason.
------
Option Compare Database

Private Sub CarePlan_Click()
On Error GoTo Err_CarePlan_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "CarePlan"
If Me.Dirty Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
stLinkCriteria = "[PSAID]=" & Me![PSAID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "PSAFiles"

Exit_CarePlan_Click:
Exit Sub

Err_CarePlan_Click:
MsgBox Err.Description
Resume Exit_CarePlan_Click

End Sub
-------
 
Do you mean you need to create a record in CAREPLAN when clicking on CarePLan?

Then you need an INSERT Statement, not an Open-Criterion.
Something like

....
DoCmd.RunSQL "INSERT Into CAREPLAN (PSAID) VALUES (" & Me![PSAID] & ")
DoCmd.OpenForm stDocName, , , stLinkCriteria
...

PS: What do you mean with "not working"?
Error message? If yes, which?

Regards,
MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
There is no error message. NOTHING happens. and i do mean NOTHING.

I copied this procedure from something else that I did, and it works there. OF course I changed the names of the forms to match.

Yes, it needs to create a record in CarePlan. The PSAID in CarePlan must be the same as the Autonumber just created in PSAFiles as the PSAID.
 
I think I got it now. I think the "Me.dirty" part was screwing it up. Now I just have to delete that module I didn't mean to create.

The only thing is now it's asking if I want to save changes to PSA Files *argh* this shouldn't be so hard.
 
Okay, that won't work Because I don't want it to ASK if I want to save. I need it to just save without asking and go directly to CarePlan
 
Let me try to explain again. PSAFiles has a PSAID field. This is an autonumber.

When I click on the button it needs to Open "CAREPLAN" automatically put the PSAID from PSAFiles into the field "PSAID" in CarePlan AND immediately start a new record for entry with PSAID in the field.

It then needs to close PSAFiles WITHOUT asking do you want to save.

 
MORE information that might help.

These are two different Tables, also.
 
I have played around a bit, and this works fine on my machine:
[blue]
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT Into CAREPLAN (PSAID) VALUES (" & Me![PSAID] & ")
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Save
DoCmd.SetWarnings True
[/blue]
P.S: I hope, PSAID is not an autonumber field in CAREPLAN, is it?
If so - change to simple numeric (long integer) field.
 
No, it's not autonumber in care plan. Let me try that. If you would like you can AIM me "troix1". I'd GREATLY appreciate it.
 
it's still not opening the new one *banging head*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top