473,382 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Find end of string

Hello,

I hope someone can help me, I have the below code, this runs on every click of the button - what I would like it to do is instead of replace the current text in [AssignedBy1], if possible I would like it to add on after the comma ? (I would like it to work as an audit trail) - Any help would be greatly appreciated - I am gathering it needs to be a ".Find"," Then ?????"
Expand|Select|Wrap|Line Numbers
  1. Private Sub ChangeOwner_Click()
  2. On Error GoTo Err_ChangeOwner_Click
  3.  
  4. FullName = DLookup("Name", "useraccessnames", UserName = getUserID)
  5.  Me.AssignedBy1 = FullName & Date & ","
  6.  
  7.     Dim stDocName As String
  8.   stDocName = "qry_ChangeOwner_AssetServices_Update"
  9.   DoCmd.OpenQuery stDocName, acNormal, acEdit
Thanks
Nigel
Oct 1 '09 #1
27 4220
ajalwaysus
266 Expert 100+
@NigelBrown
I may not understand the question fully, but would this work?

Expand|Select|Wrap|Line Numbers
  1.  Me.AssignedBy1 = Me.AssignedBy1 & "," & FullName & Date & ","
That way you take what you already have and just add on to the end of it and then reassign it to the field.

Also as NeoPa will most likely fix later, please wrap all your code in [code] brackets.

-AJ
Oct 1 '09 #2
NeoPa
32,556 Expert Mod 16PB
@ajalwaysus
You probably want to leave off the trailing ",", but otherwise this should be what you're looking for Nigel.
@ajalwaysus
Spot on AJ. Please remember for next time Nigel.
Oct 1 '09 #3
NeoPa
32,556 Expert Mod 16PB
It's just occurred to me that it may be possible to add the first one using this method. If so, some slightly different code would be required to avoid starting with a ",".
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 = (Me.AssignedBy1 + ",") & FullName & Date()
See Using "&" and "+" in WHERE Clause for the explanation.
Oct 1 '09 #4
Thanks guys - it does work but I need it to update the string i.e if the field AssigedBy1 already has for example:

User25/09/2009,User29/09/2005,

Anytime the button is clicked I would like it to add the new info, i.e if it was pressed today it would add onto the string User02/10/2009 so it would look like User25/09/2009,User29/09/2005,User02/10/2009 and so on.

It is to track records that get allocated to different departments until they are resolved, the reason I thought about the comma was to give the code something to find - in this case it would want to find the last comma and then update with User & Date. The code above does add on the end of the string but it also updates to todays date only - it over writes any previous info.

Thanks - really appreciate your time
Oct 2 '09 #5
NeoPa
32,556 Expert Mod 16PB
I'm confused. Which code above?

Have you tried the code in post #4? Does it not work for you exactly? If not please explain clearly what is different from what you require.
Oct 2 '09 #6
Yes I have tried the code in #4 - it applies the User and a date, but overwrites any data that is already in [AssignedBy1]. I need it to add on the end of the current string - i.e. if [AssignedBy1] already has "User01/10/2009" (assuming that it was done yesterday) then today if the on click was activated i would like it to show "User01/10/2009,User02/10/2009" and so on - if this is possible ?
Thanks
Oct 2 '09 #7
ajalwaysus
266 Expert 100+
Nigel,

Are you assigning anything to Me.AssignedBy1 before this line of code, because there is no reason why this code does not take what is already in Me.AssignedBy1 (i.e. "User25/09/2009") and then assign ", " and "User29/09/2005" to the end of that. If this is not working then please do a
Expand|Select|Wrap|Line Numbers
  1. Debug.Print (Me.AssignedBy1)
  2.  
before and after the line of code provided in post #4 then post the results please.

-AJ
Oct 2 '09 #8
Hi AJ,

No - AssignedBy1 will be blank to start with, I have added the debug.print and the same thing happens - it overwrites anything in AssignedBy1 with "User and the latest date (i.e today) - it does not even place a comma now i just run it on one item and below is the result :

Nigel Brown02/10/2009

This did say NigelBrown01/10/2009.

Thanks
Oct 2 '09 #9
FishVal
2,653 Expert 2GB
Did you ever follow the advices given to you in post#2 and post#4 ?
Oct 2 '09 #10
ajalwaysus
266 Expert 100+
Nigel,

This may sound condescending but I only wish to get to the bottom of this, not to offend anyone, but this doesn't make a lick of sense, so I have some questions.

1. Before you run the code provided by us, what is in Me.AssignedBy1?
2. Is Me.AssignedBy1 the field that contains the info you wish to concatenate additional info onto?

And this is a breakdown of what this code should do:
This will take the value already in the Me.AssignedBy1 field and add ", " to the end of it:
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 & ","
Then this code will add the new data you wish to add on to the end of Me.AssignedBy1:
Expand|Select|Wrap|Line Numbers
  1. & FullName & Date & ","
And then this code takes that value and puts it back into Me.AssignedBy1 overwriting what was in there originally:
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 = Me.AssignedBy1 & "," & FullName & Date() & ","
If there was no data in Me.AssignedBy1 then you will only have the new data, if there was data in Me.AssignedBy1 then this will add the new data on to the end, there is no reason I can see why this isn't happening.

-AJ
Oct 2 '09 #11
Its OK - I am prob missing something here (and yes FishVal I have followed 2 & 4) - below is what I have so far - as I run this agreed if the field is blank then the info is fine (this works) if the filed currently holds a value then is gets overwritten.
Expand|Select|Wrap|Line Numbers
  1. FullName = DLookup("Name", "useraccessnames", UserName = getUserID)
  2. Debug.Print
  3.  Me.AssignedBy1 = Me.AssignedBy1 & "," & FullName & Date & ","
  4. Debug.Print (Me.AssignedBy1)
Answer to your questions 1. Either the above value or blank (this depends on wether a user has allocated it yet to a new dept) and 2. and yes {AssignedBy1] is the field that I wish to concatenate info onto.
Oct 2 '09 #12
FishVal
2,653 Expert 2GB
Well.

The only thing I could suggest you is to debug calculation in
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 = Me.AssignedBy1 & "," & FullName & Date & ","
  2. Debug.Print (Me.AssignedBy1)
  3.  
code line.
Put a breakpoint on it and trigger the code. When execution stops on the breakpoint (if ever) check what Me.AssignedBy1 and Date returns and what value has FullName variable.
Oct 2 '09 #13
This is based on Me.AssignedBy1 already having "NigelBrown01/10/2009"

when the code is run again the debug shows Me.AssignedBy = NigelBrown02/10/2009, FullName = NigelBrown and Date=02/10/2009. It will then overwrite the original text of NigelBrown01/10/2009 not add to the string. Dont worry about it guys I will find a solution somehow - thanks for all the help anyway. Just to bear in mind this is not a text box that I am updating but a field from a query that I am viewing through a Form if this changes anything?
Oct 2 '09 #14
FishVal
2,653 Expert 2GB
...
when the code is run again the debug shows Me.AssignedBy = NigelBrown02/10/2009
...
I guess you've meant Me.AssignedBy1. If so, then the value is overwritten before the code runs.
Oct 2 '09 #15
NeoPa
32,556 Expert Mod 16PB
Nigel,

I'm off out to celebrate my Anniversary tonight so I have little time. I would just point out that your code does not reflect the code in post #4. That code should give you exactly what you're asking for. If it doesn't then it's a fair bet that you've not copied it correctly.

I will revisit this over the weekend, so please let me know how you get on (please try it again). I will respond depending on your reported findings.
Oct 2 '09 #16
Hi,
Hope you had a good weekend neopa - I have tried the code below and it still does the same thing - it overwrites the data that is already in Me.AssignedBy1 ? I appologise if I am doing this wrong? i.e I just run it where Me.Assignedby1 = "MikeWhite02/10/2009" I expected after I run it for Me.AssignedBy1 to = "MikeWhite02/10/2009,NigelBrown05/10/2009"
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 = (Me.AssignedBy1 + ",") & FullName & Date()
but it overwrite the original text to just show "NigelBrown05/10/2009.
Oct 5 '09 #17
NeoPa
32,556 Expert Mod 16PB
This is very strange Nigel. Can you post your whole procedure for me please.

Also, can you add these lines before and after that line. It should actually end up as this :
Expand|Select|Wrap|Line Numbers
  1. MsgBox Me.AssignedBy1
  2. Me.AssignedBy1 = (Me.AssignedBy1 + ",") & FullName & Date()
  3. MsgBox Me.AssignedBy1
Lastly, post the values printed as they appear (both before and after the line that updates it). I'm intrigued by this. It is behaving most strangely if all you say is true.

PS. Don't forget the CODE tags around your code. This is mandatory because it's pretty illegible without.
Oct 5 '09 #18
its ok Neopa - the code does work - I was setting me.assignedby1 to null after the code had run (full procedure below) - however if I wanted to run the code against the form instead of a txtbox - can this be done? when I try and run the code directly to a field on the form i get a Write Confilct error with options Save Record, Copy to Clipboard, Drop Changes ? anyway around this ? after the user is applied the procedure runs an update query which takes Me.Assignedby1 and applies it to a field ina query (was trying to do it this way to avoid the confict error)?
Expand|Select|Wrap|Line Numbers
  1. Private Sub ChangeOwner_Click()
  2. On Error GoTo Err_ChangeOwner_Click
  3.  
  4. DoCmd.SetWarnings False
  5.  
  6. FullName = DLookup("Name", "useraccessnames", UserName = getUserID)
  7.  
  8. Me.AssignedBy = (Me.AssignedBy + ",") & FullName & Date
  9.  
  10.     Dim stDocName As String
  11.  
  12.      stDocName = "qry_ChangeOwner_AssetServices_Update"
  13.  
  14.     If msgbox("Are you sure you want to Change the owner", vbYesNo, "Change Owner") = vbYes Then
  15.  
  16.     'DoCmd.Save
  17.  
  18.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  19.     DoCmd.Requery
  20.  
  21.     Else
  22.  
  23.     'Me.AssignedBy1 = Null
  24.     GoTo Exit_ChangeOwner_Click:
  25.  
  26.  
  27. Exit_ChangeOwner_Click:
  28.     Exit Sub
  29.  
  30. Err_ChangeOwner_Click:
  31.     msgbox Err.Description
  32.     Resume Exit_ChangeOwner_Click
  33.     End If
  34.  
  35.  
  36. End Sub
Oct 5 '09 #19
Hi NeoPa - I solved it with the below - this way I can null out me.assignedBy1 and aviod the write confilct - the below is working fine (the below brings in all the values i.e User/Date from me.assigned by, applies the new user info - runs the update query then Nulls out me.assignedBy1 ready for the next update) - thanks for all your help
Expand|Select|Wrap|Line Numbers
  1. Me.AssignedBy1 = Me.AssignedBy
  2. FullName = DLookup("Name", "useraccessnames", UserName = getUserID)
  3. Me.AssignedBy1 = (Me.AssignedBy1 + ",") & FullName & Date
Oct 5 '09 #20
NeoPa
32,556 Expert Mod 16PB
Nigel,

You need to use the CODE tags when posting code. Please use the tags in future.

Administrator.

PS. Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your Profile Options (Look near the bottom of the page).
Oct 5 '09 #21
NeoPa
32,556 Expert Mod 16PB
Good for you Nigel. I'm pleased you resolved your problem.

I was just bracing myself to read through it all properly to understand what was going on when you posted. Nice timing :)
Oct 5 '09 #22
Thanks NeoPa - will do - have another question regarding the code above (1 problem after another and this I have no idea) it will now not find the user ????? it was working fine - getting very frustrating> If I add in
Expand|Select|Wrap|Line Numbers
  1. getUserID = Environ("UserName")
it then errors on Object Required.
I have no idea why this is now happening as have not changed anything other than what we have discussed.
Oct 5 '09 #23
Hi neoPa - It seems the DLookup is not working now
Expand|Select|Wrap|Line Numbers
  1. FullName = DLookup("Name", "useraccessnames", UserName = getUserID)
The getUserID is picking up the userID but "UserName" is saying null - I have copied in my table that it is refering to below - any help would be good

The table name is : useraccessnames, and the field names are UserName and Name: as follows:

UserName Name


At the moment now it is only picking up the first name in the table.
thanks
Oct 5 '09 #24
Again - my appologies to this forum - I have resolved this now so please ignore my previous note - Neo I have adjusted my Dlookup as below.
Expand|Select|Wrap|Line Numbers
  1. FullName = Nz(DLookup("Name", "useraccessnames", "UserName = '" & getUserID & "'"), True)
It seems to work now - but please feel free to advise if I have any potential errors in here. Thanks again to all that posted.
Oct 5 '09 #25
NeoPa
32,556 Expert Mod 16PB
@NigelBrown
Absolutely no problem with that Nigel. Most of us have put posts in we've later realised weren't required after some further thought. Perfectly normal.
@NigelBrown
I can't imagine that the value you want to put in [FullName], assuming the DLookup() resolves to Null, would be True. Are you sure this is correct.

As for the DLookup() call itself -Spot on.
Oct 5 '09 #26
You are right NeoPa, I have now set this to False - my appologies - have not done VBA code for a couple of years so refreshing my memory - thanks for all your help - got me out of a hole.
thanks again
Oct 6 '09 #27
NeoPa
32,556 Expert Mod 16PB
I'm still a little confused Nigel. Surely [FullName] would require a textual value. Both True & False are boolean values. I can't see how that would make sense (whichever is used).
Oct 6 '09 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
8
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
3
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the...
3
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*>...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
4
by: KL | last post by:
Hello again, I am still working on this homework assignment and have hit a wall. I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a...
7
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
11
by: Ko van der Sloot | last post by:
Hello I was wondering which behaviour might be expected (or is required) for the following small program. I would expect that find( "a", string::npos ) would return string::npos but is seems to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.