Add New Record Button

jojo86

Registered User.
Local time
Today, 22:41
Joined
Mar 7, 2007
Messages
80
I would like to know how to write code to open up my main form (FRM_PRIMARY) on a new record so that the user can add a new site without clicking another add record button.

Also, I have a button that will search for a certain record (using either the ID or Postcode of a site). How can this be done? I have not used parameters before, but I am assuming that is what is used.

Thanks for any help giving btw :)
 
Have you looked at the acFormAdd entry in the DataMode argument of the OpenForm command?
 
Ah right, didn't know that existed - very new to doing databases in Access and such on my own.

I have had a little fiddle around with it, and it works. Thank you very much for your help - no doubt I will be posting something else up on the forums soon enough (next thing to do with it is reports!)

:)
 
Last edited:
Oh, how do I do the search button? I'm not sure about that one... Can't seem to find anything in the forum about it in a simple view.
 
On your onclick event of your button put
Code:
    stDocName = "FRM_PRIMARY"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.GoToRecord , , acNewRec
That will bring your form open to a new record!

ooops alittle late on that one
 
Type Mismatch

On your onclick event of your button put
Code:
    stDocName = "FRM_PRIMARY"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    [B]DoCmd.GoToRecord , , acNewRec[/B]
That will bring your form open to a new record!

ooops alittle late on that one

I have tried the code that you gave me, but when I click the button to add a new record, it pops up an error message of Type Mismatch and wont open the form to add a new record. It gets stuck at the bold code line above (third line)

Can you help me?!
 
I have tried the code that you gave me, but when I click the button to add a new record, it pops up an error message of Type Mismatch and wont open the form to add a new record. It gets stuck at the bold code line above (third line)

Can you help me?!

That's the correct code to do what you described. It will open up the form and go to a new (Blank) record. Are you putting this code on the ONCLICK event for the command button that calls it?
 
Yeah, that is what is so weird! I can't see what it is that I am doing wrong...

Here is my code in the OnClick event:

Private Sub cmdNewSite_Click()
On Error GoTo Err_cmdNewSite_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_PRIMARY"
DoCmd.OpenForm stDocName, , , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "FRM_MENU" 'This is to shut the Menu down when I
'click the button

Exit_cmdNewSite_Click:
Exit Sub

Err_cmdNewSite_Click:
MsgBox Err.Description
Resume Exit_cmdNewSite_Click

End Sub

I appreciate your help on this one.
 
Yeah, that is what is so weird! I can't see what it is that I am doing wrong...

Here is my code in the OnClick event:

Private Sub cmdNewSite_Click()
On Error GoTo Err_cmdNewSite_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_PRIMARY"
DoCmd.OpenForm stDocName, , , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "FRM_MENU" 'This is to shut the Menu down when I
'click the button

Exit_cmdNewSite_Click:
Exit Sub

Err_cmdNewSite_Click:
MsgBox Err.Description
Resume Exit_cmdNewSite_Click

End Sub

I appreciate your help on this one.

If this is the exact code you are using, then you have one too many commas before stLinkCriteria in the highlighted line of code. It should be ...

DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Thank you! I found other things wrong with the form too, and it now works (in some sort of way).

I have something else that needs help with - my search button. I have no idea how to create one, please help! I want to be able to search by ID number or postcode.
 
Create a form with either a txtBox or combo box. create a button on that form that uses another form whose record source is a query.
set the parameters for your query where
ID=[Form]![frmSearch].[TxtBox_or_ComboBox field]
do the same for postal code
 

Users who are viewing this thread

Back
Top Bottom