"Add new record" Form

cos

Registered User.
Local time
Today, 22:04
Joined
Jul 13, 2012
Messages
81
How can i make a form open, with the default correct foreign key from a previous form, so that i can enter a new record?

i tried the "Open form" macro, and set "where condition" to equal the foreign key
( [ShopID]=[Forms]![FRM_Shop]![ShopID] )​
and that didn't seem to work..

any ideas fellers?
 
Here's a sample that demonstrates the principal. Check out the comments in the various Events.
 

Attachments

not really helping to be honest with you =(
 
Did you have a look at the On Dbl Click event of Combo2 on FRM-Records and the On Load event of FRM_Items?
 
there must be some easier way of accomplishing this for example via a macro? im no good with this code stuff =/
 
your code isn't working.. maybe its because yours involves a combo box, where as mine involves a button which just opens the form (which should be blank, ready for a new record with the correct foreign key in place)...

so how can i fix this?
 
If it's through a combo or a command button the principal is still the same.

You use the OpenArgs portion of the OpenForm method to pass information to the form being opened. This form then checks the OpenArgs in it's On Load event.
 
i got this:

Private Sub Command23_Click()

Dim lngcombo2 As Long
Dim strOpenArgs As String

strOpenArgs = Me.Command23
lngcombo2 = Me![Command23]
Me.Command23 = Null


DoCmd.OpenForm "FRM_ShopContactsAdd", , , , , acDialog, "New#" & strOpenArgs
Me.Command23.Requery


End Sub

and i got Run-time error: 438
i tried doing it as you told meh, yet it still dislikes it..
 
Try;
Code:
Private Sub Command23_Click()

Dim strOpenArgs As String

strOpenArgs = Me.YourIDFieldName

DoCmd.OpenForm "FRM_ShopContactsAdd", , , , , acDialog, "New#" & strOpenArgs

End Sub
 
nop... still opens a record which already exists.. i need for it to open a blank form =(
 
What code do you have in the On Load event of the form that is being opened?
 
this macro atm..
 

Attachments

  • On Load Macro.png
    On Load Macro.png
    59.1 KB · Views: 134
Dude, it's all in the sample I posted up there in Post #3. I've directed you to the salient portions of the code, which is all explained in the comments (that's the green bits of code), from there you will need to have a play with the code and find out what happens as you make changes. You comments and code would seem to indicate that you have spent little to no time doing any of the things I have suggested.

P.S. I don't deal in Macros.
 

Users who are viewing this thread

Back
Top Bottom