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

function working in one db but not in another?

Status
Not open for further replies.

lp2059

Technical User
May 4, 2012
2
US
HI All,
First, let me say that it is good to be back. One programmer, 4 years ago was extremely helpful and I had not posted anything since then. Thank you in advance.

I have the following two addnew record function that will add x number of records to table2(child) based on table1(Primary).
I enter 3 in [NumberInspections] in main form and three records get added on requery to the subform of table2

Number 2, Works real well in one database but Number 1 does not in the other. I've have gotten two errors with the second set of functions that I can't figure out what and I don't know enough coding as self taught myself and still a newbie. "Compile ERROR - User defined type not defined" and another error says that it can't run because it would generate duplicate records in table"
What I'm doing wrong?? Please help

Number 1
Private Sub NumberInspections_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumberInspections]
Nkey = Me.MaterialRecordID
returnOkay = MyAddFunction(indx, Nkey)
End Sub

Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.openrecordset("tblInspectionFindings_Periodic", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![MaterialRecordID] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function

Number2
Private Sub NumRecords_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumRecords]
Nkey = Me.Batch
returnOkay = MyAddFunction(indx, Nkey)
End Sub

Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.OpenRecordset("tblSamplePLM", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![Batch] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
 
Compile ERROR - User defined type not defined
Check the references.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PH,
I put the function in a another form and it somehow worked, but what did you mean by "check references"?

 
When apps run fine on one machine and not on another, or run fine in one version and not when run under a newer version, one the first things you have to think about are missing references.

If you haven't checked for this kind of thing before, here are Doug Steele's detailed instructions on how to troubleshoot the problem:

Access Reference Problems

Linq ;0)>


The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top