mark8569
08-22-2007, 02:23 AM
Hello,
I am trying to create a module that will check to see if the "fileRef" of a new record is the same as any others already created.
My main table that holds all of my records stores a fileRef over a number of fields. i.e.
123456/156/456/789/458
Would be split into fields "fielda" , "fieldb", .... "fielde".
Fielda = 123456
fieldb = 156....
fielde = 458
Using a query I assemble these fields to give the overall fileRef using the expression below:
Expr1: [fielda] & IIf([fieldb] Is Not Null,"/" & [fieldb]) & IIf([fieldc] Is Not Null,"/" & [fieldc]) & IIf([fieldd] Is Not Null,"/" & [fieldd]) & IIf([fielde] Is Not Null,"/" & [fielde])
Using a form called "fileViewNewSec1" the user can create a new file and can enter a new fileRef into the 5 different fields "fielda-e".
When the user clicks on the "save & close" button the following code will be run...
Public Sub noDuplicates()
Dim fileRef As String
Dim rs As Recordset
fileRef = Form_fileViewNewSec1.fielda
If IsNull(Form_fileViewNewSec1.fieldb) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldb
If IsNull(Form_fileViewNewSec1.fieldc) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldc
If IsNull(Form_fileViewNewSec1.fieldd) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldd
If IsNull(Form_fileViewNewSec1.fielde) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fielde
End If
End If
End If
End If
Set rs = Form_section1.RecordsetClone
rs.FindFirst "[Expr1] = " & fileRef
MsgBox rs.NoMatch
End Sub
However, even tho I know that the value of the "fileRef" variable is equal to i.e. 123456/1 a record in the "expr1" field of the "section1" form the NoMatch property is returning True.
I also tried to use the DoCmd.FindRecord also but access tell me "it isnt available right now" or something. God knows why.
Can anyone know why that might be happening or even know of any other way I can achieve my goal.
Cheers Mark
I am trying to create a module that will check to see if the "fileRef" of a new record is the same as any others already created.
My main table that holds all of my records stores a fileRef over a number of fields. i.e.
123456/156/456/789/458
Would be split into fields "fielda" , "fieldb", .... "fielde".
Fielda = 123456
fieldb = 156....
fielde = 458
Using a query I assemble these fields to give the overall fileRef using the expression below:
Expr1: [fielda] & IIf([fieldb] Is Not Null,"/" & [fieldb]) & IIf([fieldc] Is Not Null,"/" & [fieldc]) & IIf([fieldd] Is Not Null,"/" & [fieldd]) & IIf([fielde] Is Not Null,"/" & [fielde])
Using a form called "fileViewNewSec1" the user can create a new file and can enter a new fileRef into the 5 different fields "fielda-e".
When the user clicks on the "save & close" button the following code will be run...
Public Sub noDuplicates()
Dim fileRef As String
Dim rs As Recordset
fileRef = Form_fileViewNewSec1.fielda
If IsNull(Form_fileViewNewSec1.fieldb) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldb
If IsNull(Form_fileViewNewSec1.fieldc) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldc
If IsNull(Form_fileViewNewSec1.fieldd) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fieldd
If IsNull(Form_fileViewNewSec1.fielde) = False Then
fileRef = fileRef & "/" & Form_fileViewNewSec1.fielde
End If
End If
End If
End If
Set rs = Form_section1.RecordsetClone
rs.FindFirst "[Expr1] = " & fileRef
MsgBox rs.NoMatch
End Sub
However, even tho I know that the value of the "fileRef" variable is equal to i.e. 123456/1 a record in the "expr1" field of the "section1" form the NoMatch property is returning True.
I also tried to use the DoCmd.FindRecord also but access tell me "it isnt available right now" or something. God knows why.
Can anyone know why that might be happening or even know of any other way I can achieve my goal.
Cheers Mark