Simple OpenForm / acFormAdd problem

Sharky II

Registered User.
Local time
Today, 22:04
Joined
Aug 21, 2003
Messages
354
Hi there

Really simple problem here - i'm trying to open a 'product entry' form with the same 'supplierID' as the current open form (which will be the supplier details form), ready to insert a new product (that is supplied by that supplier).

When i don't have the acFormAdd part, the form opens up with the correct supplierID, but opens at the first record (instead of being armed and ready for a new record - like i want).

When i add 'acFormAdd', the form opens with a new record in 'add' mode, however the supplierID is always 0.

What am i doing wrong?

The code is below...

Code:
Private Sub addButton_Click()
On Error GoTo Err_addButton_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    DoCmd.RunCommand acCmdSaveRecord
    
    stLinkCriteria = "[SupplierID]=" & Me![SupplierID]
    stDocName = "frmProducts"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
    
Exit_addButton_Click:
    Exit Sub

Err_addButton_Click:
    MsgBox Err.description
    Resume Exit_addButton_Click
    
End Sub

Cheers!
 
Try this:
Code:
Private Sub addButton_Click()
On Error GoTo Err_addButton_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    [COLOR="Red"]Dim SupID [/COLOR]

    DoCmd.RunCommand acCmdSaveRecord
    
    [COLOR="#ff0000"]SupID = Me![SupplierID][/COLOR]
    stDocName = "frmProducts"
    DoCmd.OpenForm stDocName, , [COLOR="#ff0000"], ,[/COLOR] acFormAdd
    [COLOR="#ff0000"]Forms!frmProducts!SupplierID=SupID[/COLOR]
    
Exit_addButton_Click:
    Exit Sub

Err_addButton_Click:
    MsgBox Err.description
    Resume Exit_addButton_Click
    
End Sub
 
perfecto :)

many thanks
 

Users who are viewing this thread

Back
Top Bottom