hi Art,
you would not use Replace to STORE the data ... I modified the example that Duane gave you when you want VBA to evaluate what is there. For instance, in
If IsNull ... and then you pass a value to DLookup
FileList.ItemData(intI) is delimited with single quotes. Obviously, this will be an issue if the data itself HAS a single quote in it. You could add Replace here; however, it would be better to use a string variable to construct what you need
respectfully,
crystal
~ have an awesome day ~
Here is my code (with the debug statement), where would I put this replace statement?
Dim db As Database
Dim rs As Recordset
Dim iRecCount As Integer
Dim strDocLoc As String
Dim intI As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblDocumentMain")
iRecCount = Me.FileList.ListCount
For intI = 0 To Me.FileList.ListCount - 1
strDocLoc = Me.FileList.ItemData(intI)
Debug.Print strDocLoc
If IsNull(DLookup("DocLocation", "tblDocumentMain", "DocLocation = '" & FileList.ItemData(intI) & "'")) Then
rs.AddNew
rs!DOCLOCATION = FileList.ItemData(intI)
rs!DATEOFDOC = Date
rs!DOCUSER_ID = glngThisEmpID
rs!DOCTYPE = FileExtensionFromPath(FileList.ItemData(intI))
rs!ACTIVE = -1
rs.Update
End IfNext intI
MsgBox "You have imported " & CStr(iRecCount) & " records.", vbOKCancel
rs.Close
Set rs = Nothing
Set db = Nothing
Me!sfrmDocMain.Form.Requery
Me.FileList.RowSource = ""
With Warm Regards,Arthur D. LorenziniIT System ManagerCheyenne River Housing AuthorityWk.(605)964-4265 Ext. 130Fax (605)964-1070
"Valar Dohaeris"
From: crystal 8 strive4peace2008@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>Sent: Wednesday, August 30, 2017 07:40:24 AMSubject: Re: [MS_AccessPros] Adding file locations and filenames to a continous form
... or better yet, use Replace when the string is assigned:
strDocLoc = Replace( FileList.ItemData(intI), "'", "''")
~crystal
On 8/30/17 7:35 AM, crystal 8 strive4peace2008@yahoo.com [MS_Access_Professionals] wrote:
Hi Art,
when you refer to a value in code that might have what you are delimiting with, use Replace
For instance, if you are delimiting the value with ' then replace one ' with two '
"DocLocation = '" & Replace(strDocLoc, "'", "''") & "'"
respectfully,
crystal
~ have an awesome day ~
On 8/29/17 4:31 PM, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] wrote:
After I integrated the debug.print I found it was actually working correctly but it bombed because one of the file names contained a '. Art's Tax return.doc. So how would you handle that. Change the name of the file but there could be more than that one that contains a special character.
With Warm Regards,Arthur D. LorenziniIT System ManagerCheyenne River Housing AuthorityWk.(605)964-4265 Ext. 130Fax (605)964-1070
"Valar Dohaeris"
From: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>Sent: Tuesday, August 29, 2017 03:52:08 PMSubject: Re: [MS_AccessPros] Adding file locations and filenames to a continous form
Art,
In the debug mode, what values do you see when you hover your mouse pointer over intI and FileList.ItemData(intI)?
Have you tried using some debug.Print statements in your code?
Dim strDocLoc as StringstrDocLoc = FileList.ItemData(intI)debug.print strDocLocIf IsNull(DLookup("DocLocation", "tblDocumentMain", "DocLocation = '" & strDocLoc & "'")) Then
Regards,Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, August 29, 2017 3:16 PM
To: John Viescas JohnV@msn.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Adding file locations and filenames to a continous form
OK the add is still working but when I tried to add a duplicate I received the following error:
RUn-time Error 3075
Syntax error (missing operator) in query expression'DocLocation='c:\USers\alorenzini\Documents\Art's return 2014.pdf".
When I click debug it high lights this line:
If IsNull(DLookup("DocLocation", "tblDocumentMain", "DocLocation = '" & FileList.ItemData(intI) & "'")) Then
With Warm Regards,Arthur D. LorenziniIT System ManagerCheyenne River Housing AuthorityWk.(605)964-4265 Ext. 130Fax (605)964-1070
"Valar Dohaeris"
From: John Viescas JohnV@msn.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>Sent: Tuesday, August 29, 2017 09:54:36 AMSubject: Re: [MS_AccessPros] Adding file locations and filenames to a continous form
Missing an additional close paren at the end (before the Then).
John Viescas, AuthorEffective SQLSQL Queries for Mere MortalsMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access Applicationshttp://www.viescas.com/
If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book recommendations and all the cool links!
(Paris, France)
On Aug 29, 2017, at 4:04 PM, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
This line is turning red in in the vba editor....
If IsNull(DLookup("DocLocation", "tblDocumentMain", "DocLocation = '" & FileList.ItemData(intI) & "'") Then
With Warm Regards,Arthur D. LorenziniIT System ManagerCheyenne River Housing AuthorityWk.(605)964-4265 Ext. 130Fax (605)964-1070
"Valar Dohaeris"
From: John Viescas JohnV@msn.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>Sent: Tuesday, August 29, 2017 05:41:48 AMSubject: Re: [MS_AccessPros] Adding file locations and filenames to a continous form
Posted by: crystal 8 <strive4peace2008@yahoo.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (27) |
Tidak ada komentar:
Posting Komentar