Access

N

nbohana

My application has many forms. The main form (sales) updates three other
forms (Checker, Buildings and Estimator), 'Buildings' is a subform of sales.
The updates are ok, but saving and closing does not work, espically
'Buildings'. Closing 'Checker and Estimator does not work. What am I doing
wrong?? The code follows:

Private Sub Save_Click()
On Error GoTo Err_Save_Click

Dim stDocName As String
Dim stLinkCriteria As String

Dim bnum As Integer
Dim bsux As String

bnum = Me![bidnumber]
bsux = Me![bidsuffix]
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

stDocName = "Buildings"

stLinkCriteria = "[bid-number]=" & bnum
DoCmd.OpenForm stDocName, , , stLinkCriteria

Forms!buildings.[bid-number] = bnum
Forms!buildings.[buildings] = Forms!buildings.[buildings] + 1

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

stDocName = "Checker"

stLinkCriteria = "[bid-number]=" & bnum
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.GoToRecord , , acNewRec

Forms!checker.[bid-number] = bnum
Forms!checker.[bid-suffix] = bsux

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Rem DoCmd.Close

stDocName = "Estimating"

stLinkCriteria = "[bid-number]=" & bnum
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.GoToRecord , , acNewRec

Forms!Estimating.[bidnumber] = bnum
Forms!Estimating.[bidsuffix] = bsux

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Rem DoCmd.Close
 
J

John W. Vinson

My application has many forms. The main form (sales) updates three other
forms (Checker, Buildings and Estimator),

Ummm... No. It doesn't.

Data is NOT stored in forms. It's stored in Tables. You are updating *A
TABLE*, not a form. The other forms are just windows, tools which display data
in their recordsource table.
'Buildings' is a subform of sales.
The updates are ok, but saving and closing does not work, espically
'Buildings'. Closing 'Checker and Estimator does not work. What am I doing
wrong?? The code follows:

What specifically "doesn't work"? Do you get an error? no data saved?
Private Sub Save_Click()
On Error GoTo Err_Save_Click

Dim stDocName As String
Dim stLinkCriteria As String

Dim bnum As Integer
Dim bsux As String

bnum = Me![bidnumber]
bsux = Me![bidsuffix]
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

This is obsolete code (the wizards still use it but they're pretty outdated).
I'd suggest replacing the above by

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False
stDocName = "Buildings"

If you're opening Buildings then it is NOT a subform. A Subform is in a
Subform Control on your main form and does not need to be opened
independently.

stLinkCriteria = "[bid-number]=" & bnum
DoCmd.OpenForm stDocName, , , stLinkCriteria

Forms!buildings.[bid-number] = bnum
Forms!buildings.[buildings] = Forms!buildings.[buildings] + 1

This will overwrite whatever data is in those controls on whatever happens to
be open when you open the form. It won't add a new record. A Subform will do
so *with no code at all*.

I'd really recommend making these three forms Subforms of your main form,
using bid-number as the master/child link field.

John W. Vinson [MVP]
 

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