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

adding new data without typing in pk 3

Status
Not open for further replies.

mstekkie

Technical User
May 15, 2002
51
CA
i've got this one form with the firm number as the pk. when you click on the view employees button, it shows the employees associated with that company. problem is, when i want to add a new employee, i can't do that without inputting the firm number again.

i want the employee linked form to take the pk from the previous form. i don't want the user to have to input it again. if the pk isn't put in, then the employee isn't saved.

any ideas on how to accomplish this?

thank you.

cate :)
 
Yes, that code is inserted by the wizard. It runs a routine that displays the error, but the error occurred before that. I'd recommend setting the breakpoint on the first executable statement in save button routine. Step through it line by line until you find the line that is causing the problem. The error might not even be in the save button routine. If you get through that routine with no error, set a breakpoint in another event procedure that you suspect could be causing the problem. It might be better to post the entire contents of the save button OnClick routine.

dz
 
Private Sub btnSaveEmp_Click()
On Error GoTo Err_btnSaveEmp_Click

Me.firmNumber = [Forms]![frmCurrentClients]![firmNumber].Value

DoCmd.RunCommand acCmdSaveRecord

Exit_btnSaveEmp_Click:
Exit Sub

Err_btnSaveEmp_Click:
MsgBox Err.Description
Resume Exit_btnSaveEmp_Click

End Sub

That's all the code for the save button onclick event. All the other code for this form was made by the wizard. Since this is the only code that I changed, I figured it was safe to assume that the problem lies in here.

cate
 
Now that I looked at your message closer, the error must have been in the Exit_btnSaveEmp OnClick routine.

Resume Exit_btnSaveEmp_Click

This statement causes execution to pick up at the next line in this routine, and means that the error must have been in that routine. At least you've got it narrowed down to the right routine. lol

 
Sorry, I figured you had more code in that routine than that one statement. I don't see anything obvious that could be wrong. The only thing that I can suggest is deleting the line Me.firmNumber = [Forms]![frmCurrentClients]![firmNumber].Value and retyping it. Make sure when you type "Me.f" that firmNumber appears in the list that pops up. If it is in the list, that means it has been created properly. If it isn't in the list, that's your problem. If it is in the list, I can't see what might be wrong. There could be a problem with one of the properties of the textbox (firmNumber). Post back if firmNumber is in the list after you type in "Me.f"
 
firmNumber is in the list. I'm checking the properties of the textbox, though I'm not too sure what I'm looking for.
 
One more thing to check...

The form named frmCurrentClients must be open when the routine executes that refers to it. Are you calling the current form from that form? If not, that could be the problem. You can make sure that there is a value in [Forms]![frmCurrentClients]![firmNumber].Value by holding the mouse over it in the debugger when stepping through the code. You can also set a Watch expression by right clicking the mouse in the VB window and selecting Add Watch. Type [Forms]![frmCurrentClients]![firmNumber].Value into the field where you enter the expression.
 
Yep, I'm calling the current form from the current clients form.
 
I've run out of ideas without seeing your database. If you want to email it to me, I'll look at it and see if I can find the problem. Just post your email address and I'll reply to you.

Thanks,

dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top