rexb
01-26-2010, 12:26 PM
Hi,
How do I query using this format ("lastname,firstname")?
thanks
How do I query using this format ("lastname,firstname")?
thanks
|
View Full Version : Name with comma rexb 01-26-2010, 12:26 PM Hi, How do I query using this format ("lastname,firstname")? thanks vbaInet 01-26-2010, 12:33 PM Hi, How do I query using this format ("lastname,firstname")? thanks Show your sql. dcb 01-26-2010, 01:48 PM Select LastName & ", " & FirstName AS FullName from tblContacts order by LastName vbaInet 01-26-2010, 01:59 PM Select LastName & ", " & FirstName AS FullName from tblContacts order by LastName I would doubt a field name would have a comma in it. The poster is referring to the WHERE clause (I would have thought). dcb 01-26-2010, 02:14 PM I would doubt a field name would have a comma in it. The poster is referring to the WHERE clause (I would have thought). Field name with a comma???? Where do you see this? WHERE: Same method would apply..... vbaInet 01-26-2010, 02:34 PM Field name with a comma???? Where do you see this? WHERE: Same method would apply..... I think the poster wasn't asking how to concatenate/build an sql string simply because he/she put the string in brackets. So my guess was it could be a parameter, maybe? dcb 01-26-2010, 02:52 PM I think the poster wasn't asking how to concatenate/build an sql string simply because he/she put the string in brackets. So my guess was it could be a parameter, maybe? If thats the case then: WHERE ((LastName & ", " & FirstName) = "Inet, VBA") Simon_MT 01-26-2010, 02:53 PM I use a Dialogue Form with just two fields and then create a Criteria: Private Function ArtistsDialogueCriteria() As String With CodeContextObject ArtistsDialogueCriteria = "[Surname] like '" & .[Field1] & "*" & "' and [FirstName] like '" & .[Field2] & "*" & "'" End With End Function Then a button and use the Criteria within the OnClick Event: DoCmd.OpenForm "Artists Details", , , ArtistsDialogueCriteria, , acWindowNormal Simon vbaInet 01-26-2010, 02:57 PM I use a Dialogue Form with just two fields and then create a Criteria: Private Function ArtistsDialogueCriteria() As String With CodeContextObject ArtistsDialogueCriteria = "[Surname] like '" & .[Field1] & "*" & "' and [FirstName] like '" & .[Field2] & "*" & "'" End With End Function Then a button and use the Criteria within the OnClick Event: DoCmd.OpenForm "Artists Details", , , ArtistsDialogueCriteria, , acWindowNormal Simon I've noticed that Simon does like this CodeContextObject :) hehe! Simon_MT 01-27-2010, 11:44 AM Its a bit addictive. The real reason I use it is that I have to deal with images so wherever there Stock you have to be able to double click and bring up the image. This goes through Stock, Exhibitions, Locations, Editions, Sales, Client Interest etc so users expect to be able to get to an Image. It was easier to write one script that having one the was Form dependent. The other reason was, correct me if I'm wrong - having modules on Forms or Reports going back to Access 1997 was considered inefficient so all the scripts are in Modules which is great as I can trace every bit code. Simon rexb 01-27-2010, 11:58 AM Hello, thank you very much for this very enlightening views from everybody. I've attached my sql design. The one with the circle is actually what i'm referring too. thanks again everyone. vbaInet 01-27-2010, 12:31 PM Hello, thank you very much for this very enlightening views from everybody. I've attached my sql design. The one with the circle is actually what i'm referring too. thanks again everyone. Wrap it in quotes: "John, Doe" vbaInet 01-27-2010, 12:33 PM Its a bit addictive. The real reason I use it is that I have to deal with images so wherever there Stock you have to be able to double click and bring up the image. This goes through Stock, Exhibitions, Locations, Editions, Sales, Client Interest etc so users expect to be able to get to an Image. It was easier to write one script that having one the was Form dependent. The other reason was, correct me if I'm wrong - having modules on Forms or Reports going back to Access 1997 was considered inefficient so all the scripts are in Modules which is great as I can trace every bit code. Simon lol It was just something I noticed. It's a pretty useful method. rexb 01-27-2010, 12:37 PM Wrap it in quotes: "John, Doe" It was actually wrapped in quotes and that is the error I get. vbaInet 01-27-2010, 12:41 PM Unless I need to go to specsavers, looking at that screen shot I don't see any quotes. All I see is this: John, Doe rexb 01-27-2010, 01:15 PM Unless I need to go to specsavers, looking at that screen shot I don't see any quotes. All I see is this: John, Doe :) don't worry I can assure you I did put in the quotes before I even tried posting this issue here. :) vbaInet 01-27-2010, 01:22 PM :) don't worry I can assure you I did put in the quotes before I even tried posting this issue here. :) So that was a deceiving screenshot you put up then lol. I've just tested it and it works. Attach your db rexb 01-27-2010, 02:09 PM So that was a deceiving screenshot you put up then lol. I've just tested it and it works. Attach your db On the field "assigned to", I tried editing the names it worked, I wonder if it has something to do with the way I imported it from excel spreadsheet? Your thoughts? Thanks vbaInet 01-27-2010, 02:20 PM On the field "assigned to", I tried editing the names it worked, I wonder if it has something to do with the way I imported it from excel spreadsheet? Your thoughts? Thanks It could be that it contained spaces at the end. Maybe next time try using a wild character. Such as: Like "*John, Doe*" Also before importing and before saving it's good to Trim() your value. rexb 01-28-2010, 06:48 AM It could be that it contained spaces at the end. Maybe next time try using a wild character. Such as: Like "*John, Doe*" Also before importing and before saving it's good to Trim() your value. Thanks for the advice. So when do I trim? before or after I have imported the data? vbaInet 01-28-2010, 06:49 AM Thanks for the advice. So when do I trim? before or after I have imported the data? Before saving, unless you're absolutely positive that the data being saved would not contain spaces. |