Wrox Programmer Forums
|
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
 
Old July 3rd, 2006, 01:46 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






 
Old July 3rd, 2006, 07:41 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
 
Old July 3rd, 2006, 07:42 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, that is:

x = x + 1

Not:

X = 1 + 1


mmcdonal
 
Old July 3rd, 2006, 08:05 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Expert,

Its giving an error while debugging at:

Rs1.Fields("Lemma") = trn.String(x) as "No Current Record"

Any Idea?

Thanks,
Shailesh

 
Old July 3rd, 2006, 09:04 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
 
Old July 3rd, 2006, 09:09 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



 
Old July 3rd, 2006, 09:11 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not using Array Please ignore that line.


 
Old July 3rd, 2006, 09:13 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old July 3rd, 2006, 09:20 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am not sure what this does:

Set trn = PSL.ActiveProject.TransLists(1)

mmcdonal
 
Old July 3rd, 2006, 09:25 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding row to dataset in C# MAKO C# 2 March 11th, 2010 08:10 AM
Adding a row without using Update command wpyoung2600 ADO.NET 1 August 22nd, 2004 08:26 AM
Adding a button to each row of a datagrid badgolfer ASP.NET 1.0 and 1.1 Basics 1 March 1st, 2004 10:05 AM
Dynamically adding a row to a DataGrid vwindrow ASP.NET 1.x and 2.0 Application Design 2 August 20th, 2003 03:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.