PC Review


Reply
Thread Tools Rate Thread

check similar values before update

 
 
Francis
Guest
Posts: n/a
 
      22nd Feb 2006
Hello i have a subform textboxcontrol, that represents doccontent, and
i want to warn the user in a msgbox when he inserts a doccontent, that
exists already, and leave the option of keeping the new or the old
value. Considering i want to inform the user in a msgbox in which
docnames there are similar entries.

Also docname is on a different table(docname_Table), then Form's and
SubForm's ControlSource (doccontent_Table), which are related by docID
(it's primary key of docname_Table, and foreign key of
doccontent_Table), having came up with the following code, which is not
working in the first dlookup line:

Oh and as u can see i could just make an inner join between
docname_table and doccontent_table (reducing thus the scripts)

Private Sub txtdoccontent_BeforeUpdate(Cancel As Integer)
Dim search_doccontent, search_docID, search_docname, msgdocs

search_doccontent = DLookup("[doccontent]", "doccontent_Table",
"[doccontent_Table].[doccontent] =" &
Me![SubForm].[txtdoccontent].Value)
search_docID = IIf(IsNull(search_doccontent), "",
DLookup("[docID]", "doccontent_Table", "[doccontent]=" &
search_doccontent ))
search_docname = IIf(IsNull(search_doccontent ), "",
DLookup("[docname]", "docname_Table", "[docID]=" & search_docID ))
If Not IsNull(search_doccontent ) Then
msgdocs = MsgBox("There is already one or more docs with that
similar contents, and they are the following:" & Chr(10) & _
"Considering this click in your option.", vbOKCancel)
If msgdocs = vbCancel Then
Me.txtdoccontent.Undo
End If
End If
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
Guest
Posts: n/a
 
      22nd Feb 2006
Francis:

Try this:

Private Sub txtdoccontent_BeforeUpdate(Cancel As Integer)

Dim rst As ADODB.Recordset
Dim strSQL As String, strDocNameList As String, strMessage As String

strSQL = "SELECT docname FROM docname_Table" & _
" INNER JOIN doccontent_Table" & _
" ON docname_Table.docID = doccontent_Table.docID" & _
" WHERE doccontent = """ & Me. txtdoccontent & """" & _
" ORDER BY docname"

Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.Open _
Source:=strSQL, _
CursorType:=adOpenKeyset, _
Options:=adCmdText

With rst
Do While Not .EOF
strDocNameList = strDocNameList & ", " & .Fields("docname")
.MoveNext
Loop
End With

' remove leading comma and space
strDocNameList = Mid$( strDocNameList, 3)

strMessage = "There is already one or more docs with that " & _
"similar contents, and they are the following: " & strDocNameList & _
vbNewLine & vbNewLine & "Considering this click in your option."

If Msgbox(strMessage, vbOKCancel + vbInformation, "Warning") = vbCancel
Then
Cancel = True
Me.Undo
End If

Set rst = Nothing

End Sub

Ken Sheridan
Stafford, England

"Francis" wrote:

> Hello i have a subform textboxcontrol, that represents doccontent, and
> i want to warn the user in a msgbox when he inserts a doccontent, that
> exists already, and leave the option of keeping the new or the old
> value. Considering i want to inform the user in a msgbox in which
> docnames there are similar entries.
>
> Also docname is on a different table(docname_Table), then Form's and
> SubForm's ControlSource (doccontent_Table), which are related by docID
> (it's primary key of docname_Table, and foreign key of
> doccontent_Table), having came up with the following code, which is not
> working in the first dlookup line:
>
> Oh and as u can see i could just make an inner join between
> docname_table and doccontent_table (reducing thus the scripts)
>
> Private Sub txtdoccontent_BeforeUpdate(Cancel As Integer)
> Dim search_doccontent, search_docID, search_docname, msgdocs
>
> search_doccontent = DLookup("[doccontent]", "doccontent_Table",
> "[doccontent_Table].[doccontent] =" &
> Me![SubForm].[txtdoccontent].Value)
> search_docID = IIf(IsNull(search_doccontent), "",
> DLookup("[docID]", "doccontent_Table", "[doccontent]=" &
> search_doccontent ))
> search_docname = IIf(IsNull(search_doccontent ), "",
> DLookup("[docname]", "docname_Table", "[docID]=" & search_docID ))
> If Not IsNull(search_doccontent ) Then
> msgdocs = MsgBox("There is already one or more docs with that
> similar contents, and they are the following:" & Chr(10) & _
> "Considering this click in your option.", vbOKCancel)
> If msgdocs = vbCancel Then
> Me.txtdoccontent.Undo
> End If
> End If
> End Sub
>
>

 
Reply With Quote
 
Francis
Guest
Posts: n/a
 
      23rd Feb 2006
Hi Ken, your example was nice, but i have the following error when i
try to implement the code:
Compile Error: User-defined type not defined

In the step: Dim rst As ADODB.Recordset

Why is this happening? I'm using Microsoft Access 2003 SP2 in Visual
Basic 6.3

Francisco
Évora, Portugal

 
Reply With Quote
 
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
Guest
Posts: n/a
 
      23rd Feb 2006
Francisco:

It sounds like you don't have a reference to the ADO object library. This
is possibly due to the application having originally been created in an
earlier version of Access. Select References from the Tools menu on the VBA
menu bar and scroll down to the Microsoft ActiveX Data Objects Library (I'm
not sure what the version is for Access 2003, but try the latest one). Check
it and close the dialogue. The code should compile OK then.

Ken Sheridan
Stafford, England

"Francis" wrote:

> Hi Ken, your example was nice, but i have the following error when i
> try to implement the code:
> Compile Error: User-defined type not defined
>
> In the step: Dim rst As ADODB.Recordset
>
> Why is this happening? I'm using Microsoft Access 2003 SP2 in Visual
> Basic 6.3
>
> Francisco
> Évora, Portugal
>
>

 
Reply With Quote
 
Francis
Guest
Posts: n/a
 
      3rd Mar 2006
found a way to sort this in another fashion.

cheers

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel check box values to Access Check Box values =?Utf-8?B?QkFD?= Microsoft Access Form Coding 1 5th Sep 2006 11:19 PM
Check for duplicate values before update =?Utf-8?B?Qm9iIE11bGxlbg==?= Microsoft Access Form Coding 1 10th Jun 2004 02:34 AM
Looking up similar values =?Utf-8?B?RnJ1c3RyYXRlZCBXb3JrZXI=?= Microsoft Excel Worksheet Functions 4 20th Apr 2004 04:30 PM
Check values before form update Mr. Smith Microsoft Access Form Coding 1 2nd Feb 2004 06:55 PM
How do I create a check box or similar? Colin Microsoft Excel Worksheet Functions 2 26th Jan 2004 09:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.