 |
Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

July 3rd, 2006, 01:46 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Adding new row
Hi All,
I have table with one field, which will contain "source text" in one row and "target text" in next row of same field.
With the below vba macro i can get the source text in rows but failing to add target text in next row.
Can u pls give some idea for the same? I am running this macro in Passolo.
Sub Main
' Get a translation list
Dim trn As PslTransList
Set trn = PSL.ActiveProject.TransLists(1)
If trn Is Nothing Then Exit Sub
Dim Array1 As Variant
Dim x As Long 'Variant
Dim Db1 As DAO.Database
Dim Rs1 As DAO.Recordset
Set Db1 = DBEngine.OpenDatabase("access_schema.mdb")
Set Rs1 = Db1.OpenRecordset("Lemmas",dbOpenTable)
For x = 1 To trn.StringCount
With Rs1
.AddNew
.Fields("Lemma") = trn.String(x).SourceText 'Adding source text, next row i have to add target text which is "trn.String(i).Text "
.Fields("Lemma") = trn.String(i).Text
.Update
End With
Next
Db1.Close
End Sub
|

July 3rd, 2006, 07:41 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Hi,
Try this:
For x = 1 To trn.StringCount
Rs1.AddNew
Rs1.Fields("Lemma") = trn.String(x)
Rs1.Update
x = 1 + 1
Rs1.MoveNext
Next
Does this help? Do you see why it helps?
mmcdonal
|

July 3rd, 2006, 07:42 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Sorry, that is:
x = x + 1
Not:
X = 1 + 1
mmcdonal
|

July 3rd, 2006, 08:05 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Expert,
Its giving an error while debugging at:
Rs1.Fields("Lemma") = trn.String(x) as "No Current Record"
Any Idea?
Thanks,
Shailesh
|

July 3rd, 2006, 09:04 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You ran out of data in your array. Where are you getting that data from? I don't see it in your code.
Now I am not sure what you are trying to do with this code. It sounded like you are trying to create to new rows in a table, and populate one row after the other with data from your array. Are you trying to take data from one row and put it into another? Sorry for the confusion.
mmcdonal
|

July 3rd, 2006, 09:09 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Expert,
I getting the source strings and target strings from
Dim trn As PslTransList
Set trn = PSL.ActiveProject.TransLists(1)
If trn Is Nothing Then Exit Sub
Is from "Passolo" active project.
trn.String(x).SourceText "is the source string" from active project
trn.String(x).Text " is the target string which is in german from active project"
Both the source an target strings I have to put under one feild "Lemma" like
Lemma (Feild name)
Source text
Text
Source text
Text
Have problem how do i put in "source" than "target"?
Thanks,
Shailesh
|

July 3rd, 2006, 09:11 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am not using Array Please ignore that line.
|

July 3rd, 2006, 09:13 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
For ref:
Below is the Macro:
Sub Main
' Get a translation list
Dim trn As PslTransList
Set trn = PSL.ActiveProject.TransLists(1)
If trn Is Nothing Then Exit Sub
'Dim Array1 As Variant
Dim x As Long 'Variant
Dim Db1 As DAO.Database
Dim Rs1 As DAO.Recordset
Set Db1 = DBEngine.OpenDatabase("access_schema.mdb")
Set Rs1 = Db1.OpenRecordset("Lemmas",dbOpenTable)
Dim j As Long
For x = 1 To trn.StringCount
Rs1.AddNew
Rs1.Fields("Lemma") = trn.String(x).SourceText 'Adding source strings to Database
'Rs1.Fields("Lemma") = trn.String(x).Text 'Adding Target strings to Database
Rs1.Update
x = x + 1
Rs1.MoveNext
Next
Db1.Close
End Sub
|

July 3rd, 2006, 09:20 AM
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I am not sure what this does:
Set trn = PSL.ActiveProject.TransLists(1)
mmcdonal
|

July 3rd, 2006, 09:25 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here Passolo's Active project contains Translation List, from Translation list I am getting "source Text" that's in English and "Text" That is German.
"Trn" is the passolo's Translation List.
|
|
 |