Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to save in four data fields from one text box

Status
Not open for further replies.

cmaknp

Programmer
Aug 28, 2002
25
IN
i hv one database file

rst.field(1)
rst.field(2)
rst.field(3)
rst.field(4)

textbox1 =

"Name
Age
Sex
ClASS"

i want to save in above fields,
LIKE FIELD1 - NAME
FIELD2 - AGE
FIELD3 - SEX
FIELD4 - CLASS

PLEASE HELP ME IN CODING..I MEAN HOW TO WRITE


 
What code have you got at the moment? It will be easier to help from there!

You seem to asked 6 questions, and found none of the answers helpful. If they are helpful, let us know. If not, ask for clarification in the original thread.

Try reading the FAQ referred below for guidance Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Actually i m coding this

Text5.Text = Data1.Recordset.Fields(4) + vbCrLf + Data1.Recordset.Fields(5) + vbCrLf + Data1.Recordset.Fields(6) + vbCrLf

but when again i save data again from text5.txt to data file,

so its giving error

Data1.Recordset.Fields(4) = Mid(Text5.Text, 0, 60)
Data1.Recordset.Fields(5) = Mid(Text5.Text, 61, 120)
Data1.Recordset.Fields(6) = Mid(Text5.Text, 121, 180)

i m using above coding, pls now wud u like to help me
 
Hello Johnwm,
still awaiting ur advice
 
Are your text fields fixed length? Are you sure that text5.text is so long?
Mid(string, start, length) notMid(string, start, end)

Is there a reason why you are joing the strings up and then splitting them to save?

If you need to join then split try the Split function
Dim aryList() As String
aryList = Split(text5.text, vblf)
This give you all your strings in an array
Then :
Data1.Recordset.Fields(4) = aryList(0) Data1.Recordset.Fields(5) = aryList(1)
Data1.Recordset.Fields(6) = aryList(2)
will do what you want Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
hello john, actually...its dbf file, & i cant change that datafile in another plateform, therefore..there is some as like field..as text, "Party Name", "address", & all is 60 charector..thatswhy i wanted to save same, but i want to use 5 fields for one text box, thatswhy i m asking, now hv u got what my real problem, thatswhy i wanted that user feed data, so i can get 60 & 60 save in each field.

:)

is it disturbing u..:)), what to do, but if my procedure is wrong..so plsss guide me
 
As in my last post, the Mid function's third parameter is length of data required, not endpoint.
Perhaps your code should be something like:

Data1.Recordset.Fields(4) = Mid(Text5.Text, 0, 60)
Data1.Recordset.Fields(5) = Mid(Text5.Text, 61, 60)
Data1.Recordset.Fields(6) = Mid(Text5.Text, 121, 60)

Other than that, what error messages are you getting, and where are they coming from in your code?

As regards timing of responses, don't forget that this is done voluntarily in our own time, and it may not be possible to answer requests on a minute-by minute basis. Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
You can also use the Windows API to get a line of text from a multi-line text box:

Code:
public Const EM_GETLINE = 196

Private Declare Function SendMessageAsString Lib "user32" _
       Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
       ByVal wParam As Long, ByVal lParam As String) As Long

Public Function gsGet_Textbox_Line(cTxtBox As TextBox, lLineNo As Long) As String
 
    Dim sRetVal As String
    
    Dim lResult As Long
    
    '* * * * * * * * * * * *
            
    'Initialise the return value
    sRetVal = String(150, " ")
    
    'Make sure it is a text box
    If TypeOf cTxtBox Is TextBox Then
            
        lResult = SendMessageAsString(cTxtBox.hwnd, EM_GETLINE, lLineNo, sRetVal)
    
    End If 'cTxtBox IS a textbox
    
    gsGet_Textbox_Line = Trim$(sRetVal)
    
End Function

Note that the first line in a text box is line 0.

You could then use something like

Code:
Data1.Recordset.Fields(4) = gsGet_Textbox_Line(Text5, 0)
Data1.Recordset.Fields(5) = gsGet_Textbox_Line(Text5,1)
Data1.Recordset.Fields(6) = gsGet_Textbox_Line(Text5,2)

Hope that helps (and doesn't confuse the issue further!)

Daren
 
john, problem is coming in fst mid line, becoz mid function is retriving all text, not only 60 char.

so i think..mid is not working as per substr, pls guide once again
 
Data1.Recordset.Fields(4) = Mid(Text5.Text, 0, 60)

in above line, showing, all text from text bos in msgbox, its mean that, mid is not extracting only 0 to 60 charector,

even mid is extracting all charector text from text box, which is not suitable for field, therefore its giving error.

please once again guide,
 
I think that with Mid the first charcter is at 1, not 0.

Code:
Data1.Recordset.Fields(4) = Mid(Text5.Text, 0, 60)
should be
Code:
Data1.Recordset.Fields(4) = Mid(Text5.Text, 1, 60)

Also, if each line is only a few characters long then reading 60 will read everything in the text box. You need to know how long each line of text is (i.e. where it ends) or else make sure it is 60 characters long.

Try the API example. It works. I promise :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top