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

What is wrong with this code? (Re: popup forms)

Status
Not open for further replies.

MarkWaddington

Programmer
Aug 19, 2002
64
GB
I have this code attached to a command button, which when pressed, opens up a popup form (based on another table with a One-to-one relationship with my main form).

Private Sub EmploymentHistory_Click()
On Error GoTo Err_EmploymentHistory_Click

If Me.NewRecord Then Me.Recalc
DoCmd.OpenForm "Client_Employment", , , "[EmpNo] = Forms![Client]![RegNo]"

Exit_EmploymentHistory_Click:
Exit Sub

Err_EmploymentHistory_Click:
MsgBox Err.Description
Resume Exit_EmploymentHistory_Click

End Sub


The form opens ok, but when I enter data, then close it and open it again.. all the data I entered disappears, obviously was never stored!

Any ideas?

Thanks in advance.

Mark Waddington.
 
Hi Mark,

See if adding "acFormAdd" works:

DoCmd.OpenForm "Client_Employment", , , "[EmpNo] = Forms![Client]![RegNo]", acFormAdd

 
Thanks for the reply but it doesn't work.

The form opens ok, but nothing gets stored in it if I enter data. Also, it doesn't bring up the corresponding linked record.. just a blank form.

Any other ideas?

Thanks,

Mark.
 
If EmpNo is Text then try this:
DoCmd.OpenForm "Client_Employment", , , "[EmpNo] = '" & Forms![Client]![RegNo] & "'"

If it's a number try this:
DoCmd.OpenForm "Client_Employment", , , "[EmpNo] = " & Forms![Client]![RegNo]

Paul


 
No sorry that doesn't work :( Will I ever get this sorted?

If I use the following code it DOES work:

If Me.NewRecord Then Me.Recalc
DoCmd.OpenForm "Client_Employment", , , "[EmpNo] = Forms![Client]![RegNo]"
Forms![Client_Employment]![EmpNo] = Forms![Client]![RegNo]

But then I pay the price of having read-only users being bombarded with error messages because it tries to update a form (which read-only users can't do).

Thanks a lot for trying though, I do appreciate it! If you can think of any other ways round this problem, please let me know. I'm at my wits end!

Regards,

Mark Waddington.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top