473,396 Members | 1,749 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,396 software developers and data experts.

Splitting field value

23
I have a access database name:MainDatabase
A table inside this name:All_Table
A field inside this table,name:Login_Account
Structure of data in that field is:DOM\xyz
My question is:
How can i split this fiels value to get only'xyz'in a recordset.
Hope for some vba code and Thanks in advance.
Apr 3 '12 #1

✓ answered by NeoPa

Usha2:
Hope for some vba code
Then you should include what you already have in your question.

Assuming a recordset variable of rs, then you could access this part of the field using :
Expand|Select|Wrap|Line Numbers
  1. Split(rs!Login_Account, "\")(1)

9 2862
Rabbit
12,516 Expert Mod 8TB
You can use the Split() function and then get the second item in the resulting array.
Apr 3 '12 #2
NeoPa
32,556 Expert Mod 16PB
Usha2:
Hope for some vba code
Then you should include what you already have in your question.

Assuming a recordset variable of rs, then you could access this part of the field using :
Expand|Select|Wrap|Line Numbers
  1. Split(rs!Login_Account, "\")(1)
Apr 4 '12 #3
usha2
23
Sir,
Instead of split can i use Mid?
How can i refer to my Table ?
Is it by name"All_Table" ?
Apr 5 '12 #4
NeoPa
32,556 Expert Mod 16PB
Usha2:
Instead of split can i use Mid?
No. They are entirely separate functions.

Can you achieve similar results with code that uses Mid?
Yes, but not as easily. You're welcome to try of course.
Usha2:
How can i refer to my Table ?
Is it by name"All_Table" ?
I have no idea what you're talking about o.O
Apr 5 '12 #5
usha2
23
I want to go with Split.
Using ADODB.
I tried this ,
Expand|Select|Wrap|Line Numbers
  1. strTable = "All_Table"
  2. rstTable.Open strTable, cnnDB 'open data sources table with recordset
  3.   'Do Until rstTables.EOF 'until end of tables is reached
  4.   strnew = Split(rstTable!Login_Account, "\")(1)
  5.     Debug.Print strnew
This shows the error msg:
Run Time error'91':
Object variable or With block variable not set
May be Error in openingg recordset.
Please rectify my code and Thank U so much.
Apr 6 '12 #6
Mihail
759 512MB
Here you have a sketch for how to read/write data from/into a table or a query.
Note that the query must be updatable in order to write in.

I wish to thanks to SmileyCoder for this routine !
I make some minor (cosmetic) changes so, if something do not work, is my fault. :)

Expand|Select|Wrap|Line Numbers
  1. Dim DB As DAO.Database 'Dimension a variable for a general database
  2.     Set DB = CurrentDb() 'Assign current database to this variable (can be assigned any database, not only the current one)
  3. Dim Rst As DAO.Recordset 'Dimension a variable for a record set from DB database
  4.     Set Rst = DB.OpenRecordset("TableName") 'Assign ta recordset to this variable (can be a table or a query)
  5.     Rst.MoveFirst 'Pointer to the first record
  6.     Do While Not Rst.EOF() 'Do for all records
  7.         With Rst 'Using Rst
  8.             .Edit 'Prepare to Edit
  9.             !fldName = .... 'The field "fldName" from your Rst will be updated to ...
  10.             '............. other code
  11.                 MsgBox(!fldName) 'The field have not (yet) the new value
  12.             .Update 'NOW the "fldName" field is updated in the table
  13.                 MsgBox(!fldName) 'Now, the field have the new value
  14.             .MoveNext 'Move to the next record
  15.         End With 'End to eork with this Rst
  16.     Loop
  17.  
  18. 'Clear the variables in order to free memory
  19.     Rst.Close
  20.         Set Rst = Nothing
  21.     DB.Close
  22.         Set DB = Nothing
Apr 7 '12 #7
NeoPa
32,556 Expert Mod 16PB
If All_Table is a table in your current database then you probably want to use DAO rather than ADODB (as I guess you're using). The reference to the table object would then be :
Expand|Select|Wrap|Line Numbers
  1. Dim cdb As DAO.Database
  2. Dim rst As DAO.Recordset
  3.  
  4. Set cdb = CurrentDb()
  5. Set rst = cdb.TableDefs("All_Table").OpenRecordset(dbOpenTable, ...)
You cannot open a recordset of a String variable as your code seems to be attempting.
Apr 8 '12 #8
usha2
23
Refering field value with the symbol "!" ,AMAZING.
It was new for me also works magically,successfully.
Really the name of yours"EXPERT" justified.
Apr 10 '12 #9
NeoPa
32,556 Expert Mod 16PB
Thank you.

In truth, the bang (!) character is fairly commonly used in VBA and generally works as a shortcut to a default collection of some kind. In this case the .Fields collection of a DAO.Recordset object. So :
Expand|Select|Wrap|Line Numbers
  1. rs!Login_Account
could equally be written as :
Expand|Select|Wrap|Line Numbers
  1. rs.Fields("Login_Account")
Apr 10 '12 #10

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

Similar topics

2
by: Patrick | last post by:
I currently us JavaScript to populate a hidden field with my scroll location in order to retain the page location when I post the page back to itself. However, I don't know how to pass that hidden...
4
by: GavMc | last post by:
Hello I am new to internet programming and wonder if anyone can help me with this.... I am trying to pass a hidden field value on a form into another field on the form so that it can then be...
1
by: J | last post by:
Situation - Using the table pubs.titleauthor in a strongly typed dataset, attached to a datagrid, using the datagrid I would like to set the royaltyper field = null (the database allows nulls in...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
6
by: KDCinfo | last post by:
Although I'm making an ajax call, this is really a javascript question (although it could be even more of an HTML or DOM question... not exactly sure) I'm doing an ajax call to a remote php...
2
by: Brave | last post by:
I'm hoping someone can help me with a small issue. I have an asp page that displays informaton from an Access database. I want to create a form that allows users to display only data that...
3
by: sylver | last post by:
To convert "12q" to "12": var text = "12q"; var twelve = parseInt(text); //twelve == 12 or you can user parseFloat()..depends on your needs :D
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
by: Virtuo | last post by:
Hi people... I am new to dotNet, specially to ADO.NET Entity framework. I have a problem... I can not find a way to get field value from current active row! Here is a code I use : using...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.