[RESOLVED] Access: Sub or Function not defined
I have two separate forms (not subforms or anything. just two normal forms), one of which is linked to my data table, and the other one is a sort of welcome screen which allows the user to find records and create new records. Unfortunately, the creating of records isn't working as well as I'd like.
The way I have it set up right now is the user types either the name they want to search for or the name they want to add, and clicks the appropriate button.
Here's the welcome screen code:
Code:
Sub cmdNew_Click()
txtName.SetFocus
newEmployee = txtName.Text
DoCmd.OpenForm "Page1"
DoCmd.GoToRecord acDataForm, "Page1, acNewRec"
populateNewRecord newEmployee
End Sub
and the data form code:
Code:
Public Sub populateNewRecord(newEmployee As String)
txtEmployeeName.Text = newEmployee
End Sub
As you can see, in an effort to automatically populate the name, I'm saving the contents of the text box, and sending it off to a function in the data form. Unfortunately, it's telling me that it's not defined, and I have no idea how to fix it. :/
Re: Access: Sub or Function not defined
Just taken another look at the code. Try:
vb Code:
Sub cmdNew_Click()
txtName.SetFocus
newEmployee = txtName.Text
DoCmd.OpenForm "Page1"
DoCmd.GoToRecord acDataForm, "Page1", acNewRec
populateNewRecord(newEmployee)
End Sub
~ James
Re: Access: Sub or Function not defined
Re: Access: Sub or Function not defined
OK, I've just duplicated what you have here:
Move:
vb Code:
Public Sub populateNewRecord(newEmployee As String)
txtEmployeeName.Text = newEmployee
End Sub
to a new module. Save it, watch it run :) (I hope).
(Make sure you make those other changes I've suggested above, otherwise they will cause problems too).
Re: Access: Sub or Function not defined
Thanks! It's working great now.
(Although I can't believe I had the quotes in my GoToRecord line so messed up...http://i16.photobucket.com/albums/b4...emot-eng99.gif)
Re: [RESOLVED] Access: Sub or Function not defined