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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Button

Status
Not open for further replies.

brxmas

Programmer
Feb 9, 2004
69
0
0
US
I'm trying to add a new record in my form using a 'Command Buttom'. Below is my code.

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click
Dim intnewrec As Integer
stDocName = "frmrentals"
DoCmd.GoToRecord , , acNewRec
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub

When I click on the Command Button nothing happens. A new record isn't generated. What am I doing wrong? Thanks in advance for your help.
 
Is this a subform you want to add records too?
I think you need to set focus ????
Try remarking out these two lines and see what happens
' Dim intnewrec As Integer
' stDocName = "frmrentals"
did you rename your button? Command11 is generic?
Put a stop, press "F9" on this line
DoCmd.GoToRecord , , acNewRec
and make sure it is infact coming into that subroutine.

It won't let you add a record once it stops and shows the VB code window.




DougP, MCP, A+
 
Doug,

There is no subform, I'm adding records to the form itself.

Private Sub Command44_Click()
On Error GoTo Err_Command44_Click
Dim intnewrec As Integer
stDocName = "frmrentals"
DoCmd.GoToRecord , , acNewRec
Exit_Command44_Click:
Exit Sub

Err_Command44_Click:
MsgBox Err.description
Resume Exit_Command44_Click

End Sub

I did a F9 but nothing happens. What am I doing wrong? Thanks again for your help.
 
Then why not simply this:


Private Sub Command44_Click()
On Error GoTo Err_Command44_Click

DoCmd.GoToRecord , , acNewRec

Exit_Command44_Click:
Exit Sub

Err_Command44_Click:
MsgBox Err.Description
Resume Exit_Command44_Click

End Sub
 
How are ya brxmas . . .

It sounds like when you click the button you expect to goto a new record with certain fields automatically holding data. is this corect? . . .

Calvin.gif
See Ya! . . . . . .
 
Did you check "Event Procedure" is selected on button's Click Event?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Well this code does nothing
Dim intnewrec As Integer
stDocName = "frmrentals"

If you want to set focus to the form it would be
Forms![Formname].setfocus
But if it is the only form and no subforms you don't need to set focus.
If nothing is happening when you click the button then somehow you are not looking at the right code.
If you press F9 on this line does it make it RED
Then when you click the button the code window should pop up and stop on that line.
If this is not happening then maybe you have corruption in the code. Try making a new form and just adding an Add Rec button and see if it works on that new form.
If so then you have corruption on that form. Try compacting and repairing it might work or it might not.
Other wise you have to creates the form over.

Good luck



DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top