H
hermanko
Hi,
I have a main form that has a subform embedded, both with the same
underlying table. The table contains information about documents (i.e.
file name, location, version, and a unique file code for each). Note
that the [File Code] is not a prim key as there can be multiple copies
of one document in the table, each with a different version (i.e.
different version, last modified date, etc).
I have a button that opens a form to allow the user to input info for a
new version of the same file (i.e file code). the form disables the
File Code text box and forces the user to input something into certain
fields (i.e. [Version] and [Last Modified]).
My problem comes when I want to check that the input text box called
[txt5] which represents [Version] in my table is unique. It does not
make sense to input a value that already exists if you are added a new
version.
I tried to use a Dcount to do the error check but i get a msg saying
there is a type mismatch. The field properties in my table is set as
TEXT so i am not sure why the type mismatch occurs in comparing with
the textbox inputs. The code is shown below. If anyone can look at this
and let me know what I can do to fix it, I would be very thankful!
~Herman
Option Compare Database
Private Sub cmd_update_Click()
On Error GoTo myerror_Click
Dim i As Long
Dim db As Database
Dim rs As Recordset
If MsgBox("Update version for document " & [txt1] & "?", vbOKCancel +
vbDefaultButton1) = vbOK Then
OK = True
i = Forms![frmDocumentBrowser].CurrentRecord
Set db = CurrentDb
Set rs = db.OpenRecordset("tblDocList", dbOpenDynaset)
With rs
.AddNew
![File Code] = Me![txt1]
![File Name] = Me![txt2]
![File Location] = Me![txt3]
![Description] = Me![txt4]
![Version] = Me![txt5]
![Created By] = Me![txt6]
![Last Modified] = Me![txt7]
![Modified By] = Me![txt8]
![Comments] = Me![txt9]
.Update
End With
rs.Close
Set rs = Nothing
Set db = Nothing
If DCount("[Version]", "tblDocList", "[File Code] = " & Me![txt1] &
"AND [Version] = " & Me![txt1]) > 1 Then
MsgBox "The document version must be unique.", vbCritical
Exit Sub
End If
'close form
DoCmd.Close acForm, "frmNewVersion"
'requery
Forms![frmDocumentBrowser].Requery
DoCmd.GoToRecord acDataForm, "frmDocumentBrowser", acGoTo, i
Forms![frmDocumentBrowser].[cmd_cancelupdate].SetFocus
End If
Exit_myerror_Click:
Exit Sub
myerror_Click:
If Err.Number = 3314 Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Document information must be entered for all fields
with an asterisk (*).", vbCritical, "Invalid Date"
Else
MsgBox "Error #: " & Err.Number & vbCr & Err.Description
End If
Resume Exit_myerror_Click
End Sub
I have a main form that has a subform embedded, both with the same
underlying table. The table contains information about documents (i.e.
file name, location, version, and a unique file code for each). Note
that the [File Code] is not a prim key as there can be multiple copies
of one document in the table, each with a different version (i.e.
different version, last modified date, etc).
I have a button that opens a form to allow the user to input info for a
new version of the same file (i.e file code). the form disables the
File Code text box and forces the user to input something into certain
fields (i.e. [Version] and [Last Modified]).
My problem comes when I want to check that the input text box called
[txt5] which represents [Version] in my table is unique. It does not
make sense to input a value that already exists if you are added a new
version.
I tried to use a Dcount to do the error check but i get a msg saying
there is a type mismatch. The field properties in my table is set as
TEXT so i am not sure why the type mismatch occurs in comparing with
the textbox inputs. The code is shown below. If anyone can look at this
and let me know what I can do to fix it, I would be very thankful!
~Herman
Option Compare Database
Private Sub cmd_update_Click()
On Error GoTo myerror_Click
Dim i As Long
Dim db As Database
Dim rs As Recordset
If MsgBox("Update version for document " & [txt1] & "?", vbOKCancel +
vbDefaultButton1) = vbOK Then
OK = True
i = Forms![frmDocumentBrowser].CurrentRecord
Set db = CurrentDb
Set rs = db.OpenRecordset("tblDocList", dbOpenDynaset)
With rs
.AddNew
![File Code] = Me![txt1]
![File Name] = Me![txt2]
![File Location] = Me![txt3]
![Description] = Me![txt4]
![Version] = Me![txt5]
![Created By] = Me![txt6]
![Last Modified] = Me![txt7]
![Modified By] = Me![txt8]
![Comments] = Me![txt9]
.Update
End With
rs.Close
Set rs = Nothing
Set db = Nothing
If DCount("[Version]", "tblDocList", "[File Code] = " & Me![txt1] &
"AND [Version] = " & Me![txt1]) > 1 Then
MsgBox "The document version must be unique.", vbCritical
Exit Sub
End If
'close form
DoCmd.Close acForm, "frmNewVersion"
'requery
Forms![frmDocumentBrowser].Requery
DoCmd.GoToRecord acDataForm, "frmDocumentBrowser", acGoTo, i
Forms![frmDocumentBrowser].[cmd_cancelupdate].SetFocus
End If
Exit_myerror_Click:
Exit Sub
myerror_Click:
If Err.Number = 3314 Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Document information must be entered for all fields
with an asterisk (*).", vbCritical, "Invalid Date"
Else
MsgBox "Error #: " & Err.Number & vbCr & Err.Description
End If
Resume Exit_myerror_Click
End Sub