Public Function CreateIDs()
Dim strArt As String
Dim strPart As String
Dim strConcat As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strNewPK_Nr As String
'Set database to the current application
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryFindLast_FileNr")
strLastPK_Nr = rst!MaxNr.Value
With rst
.MoveLast
End With
strArt = Me.ARTICLE.Value 'Data selected by user from combo box
strPart = Me.PART.Value 'Data selected by user from combo box
strConcat = strArt & "-" & strPart & "-"
'Here where the problem is ("[PK_FILE_NUMBER] Like '"*" &
"[strConcat]" & "*"')!!!
strNewPK_Nr = DMax("[pk_file_number]", "[qryFindLast_FileNr]",
"[PK_FILE_NUMBER] Like '"*" & "[strConcat]" & "*"')
strNewPK_Nr = CInt(strNewPK_Nr) + 1
Me.MaxNr = strNewPK_Nr
End Function
Thanks
Angie
Angie
Firstly, it appears that you don't need to declare the Recordset and Database
objects - they are not being used. Secondly, the double quotes around strConcat
are required - it will make Access concatenate [strConcat] into the criteria,
rather than the value from this string. Finally, it looks like the last single
quote is outside the double quotes. Try this instead:
strNewPK_Nr=DMax("[pk_file_number]","[qryFindLast_FileNr]","[PK_FILE_NUMBER]
Like ' * " & strConcat & " * ' ")
I've left spaces between the single and double quotes in the criteria for
visibility - in practice they wouldn't be needed. You might also be able to
base this DMax directly on the table, rather than a query.
You should also cater for the possibility of the first record being entered
into the table, in which case DMax will return Null, by using the Nz function
(ie Nz(DMax(.....)))
Jon
Access tips & tricks - http://www.applecore99.com
Microsoft Access webring - http://a.webring.com/hub?ring=microsoftaccess