Word 2007 VBA - Can't Move around in a Recordset - From a Beginner

[reposted from the VB.net forum where I mistakenly posted it]
Hi,
This is a simple program.  The issue is that Recordset.MoveNext and .MovePrevious aren't working, though .MoveFirst and MoveLast are.  If I exchange MoveLast for MoveNext and MovePrevious to MoveNext, the output will be 8 repetitions of the last record
as compared to the first.  Counter will be 0 for each output starting with MoveFirst and 7 starting with MoveLast (which is interesting since I read that the AbsolutePosition property is supposed to be 1-based).  Any help will be appreciated!  The
recordset is default (table-based) but this issue remained when I changed it to a dynaset recordset.
Following is the code:
Private Sub CmbOffices_Click()
    Call WordEx 'opens a Word doc and sets database objects
    Dim Counter As Long
    Dim intComboItem As Integer
    Set objSelection = objWord.Selection
    objSelection.TypeText ("STUFF") & vbCrLf
    For intComboItem = 0 To CmbOffices.ListCount - 1
        recordset.MoveFirst
        Counter = recordset.AbsolutePosition
            objSelection.TypeText field.Value & field2.Value & field3.Value & Counter &
vbCrLf
              'Else
        recordset.MoveNext
        'End If
    Next
    recordset.Close
    db.Close
End Sub
Chiroacuman

Hi Gill,
Thanks for helping me with this.  I forgot to mention that I have spent a lot of time on the net and here trying to find a solution.  Here is the code where I defined variables:
[General Declarations in a classic Module]
Public db As DAO.Database
    Public recordset As DAO.recordset
    Public field As DAO.field
    Public field2 As DAO.field
    Public field3 As DAO.field
Public Sub WordEx()
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Add
    Set db = CurrentDb
    Set recordset = db.OpenRecordset("Headers", dbOpenDynaset)
    Set field = recordset.Fields(0)
    Set field2 = recordset.Fields(1)
    Set field3 = recordset.Fields(2)
    objWord.Visible = True
End Sub
Chiroacuman

Similar Messages

  • Can't Move Around in my Recordset

    Hi,
    From a beginner, the issue is that Recordset.MoveNext and .MovePrevious aren't working, though .MoveFirst and MoveLast are.  If I exchange MoveLast for MoveNext and MovePrevious to MoveNext, the output will be 8 repetitions of the last record as compared
    to the first.  Counter will be 0 for each output starting with MoveFirst and 7 starting with MoveLast (which is interesting since I read that the AbsolutePosition property is supposed to be 1-based).  Any help will be appreciated!
    Following is the code:
    Private Sub CmbOffices_Click()
        Call WordEx 'opens a Word doc and sets database objects
        Dim Counter As Long
        Dim intComboItem As Integer
        Set objSelection = objWord.Selection
        objSelection.TypeText ("STUFF") & vbCrLf
        For intComboItem = 0 To CmbOffices.ListCount - 1
            recordset.MoveFirst
            Counter = recordset.AbsolutePosition
                objSelection.TypeText field.Value & field2.Value & field3.Value & Counter & vbCrLf
                  'Else
            recordset.MoveNext
            'End If
        Next
        recordset.Close
        db.Close
    End Sub

    If you are a beginner, then don't start with a language from the last millenium. VB6 is not supported anymore for a long time.
    As this forum is about VB.Net only, have a look at the following link and consider posting in the therein linked forum:
    Visual Basic 6.0 Resource Center
    Armin

  • Word 2007 VBA vs Word 2010 VBA - Macro Failure

    Hi,
    I have a macro that when run in Word 2007 VBA works fine (Takes a Word Template, an Excel Spreadsheet and produces PDF output of merged documents).
    Sub mergethem_be() '
    ' merge1record_at_a_time Macro
    Dim fd As FileDialog
    'Create a FileDialog object as a Folder Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
    'Use the Show method to display the Folder Picker dialog box and return the user's action.
    'The user pressed the button.
    If .Show = -1 Then
    For Each vrtSelectedItem In .SelectedItems
    'vrtSelectedItem is aString that contains the path of each selected item.
    'You can use any file I/O functions that you want to work with this path.
    'This example displays the path in a message box.
    SelectedPath = vrtSelectedItem
    Next vrtSelectedItem
    Else
    MsgBox ("No Directory Selected. Exiting")
    Exit Sub
    End If
    End With
    'Set the object variable to Nothing.
    Set fd = Nothing
    Application.ScreenUpdating = False
    MainDoc = ActiveDocument.Name
    ChangeFileOpenDirectory SelectedPath
    For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
    With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
    .FirstRecord = i
    .LastRecord = i
    .ActiveRecord = i
    docName = .DataFields("naam_mailing").Value & ".pdf"
    End With
    .Execute Pause:=False
    Application.ScreenUpdating = False
    End With
    ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
    ActiveDocument.Close SaveChanges:=False
    Next i
    Application.ScreenUpdating = True
    End Sub
    If there are 31 rows in the spreadsheet it produces 31 PDF documents named based on the Name field in the Mail Merge Template.
    However when I use the same Macro code in Word 2010, same mail merge template and same source excel, it produces the first PDF and then generates an error on the bolded line as if there was no longer a document available.
    Now I know I use ActiveDocument.Close before going through the loop again, but that seems fine for Word 2007.
    Am I missing something really obvious here?

    If Bernie's ideas don't work, single step thru the code. Does the first file get created properly?
    What is the error? If the file isn't created, then the ActiveDocument refers to the template which isn't good to close!
    I suspect there is a different behavior in how Word 2010 works and your VBA code probably needs to reflect that, though VBA is usually very good at providing backwards compatibility.
    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

  • I can't get rid of the message, n error occurred with the publication of album.  It just keep coming back, and can't move around in IPhoto.

    I can't get rid of the message, n error occurred with the publication of album.  It just keep coming back, and can't move around in IPhoto.

    Okay, folks, after a 3 1/2 hour phone call with a (very patient) telephone support person at Blackberry, here's what I learned.
    You can check your USB drivers this way:
    Plug in your phone into your USB drive. Assuming your Blackberry is "seen" by your computer...
    Go into the Device Manager on your computer (control panel)
    Expand the Universal Serial Bus controllers item on the bottom of the list
    Right-click on BlackBerry Smartphone and choose Properties
    Click on the Driver tab
    Click on the Driver Details button
    You should see one driver. I saw two. The one the BlackBerry likes is the RimUsb one.
    So here's what NOT to do: We tossed the entire driver that was the "extra". This effectively made using my mouse and keyboard impossible, as they are USB, and sent my poor husband into the basement to find a million-year-old keyboard (and then a mouse) with the old fashioned kind of connectors (PS2). Bleh. Don't do that.
    Here's what I did that worked (not saything this will work for you -- this modifies the Registry so better do a system backup with that backup and restore if you're nervous about this sort of thing):
    From the start menu, choose run, and type regedit to get into the Registry editor.
    Follow this file path: Computer, HKEY_LOCAL_MACHINE, SYSTEM, CurrentControlSet, Control, Class
    Click on: {36FCE60-C465-11CF-8056-4445535400000}
    If there's an item on the right called "UpperFilters", delete it. (see pictures)
    Hope this helps someone.
    Karin
    First pic: shows "before"
    Second pic: shows full file path and "after"

  • Can i move around the apps to my liking?

    Can I move around the apps to my liking?

    Yes you can. press and hold on any app you want, and it should start shaking/jiggling etc... you can then freely move any app around to your liking
    Good luck!

  • How can I move the ODI Work Repository from one server to another server?

    How can I move the ODI Work Repository from one server to another server?

    Hi,
    If you would like to move your source models, target models and project contents from Work repository 1 to another work repository.
    I.e. Dev. server to Prod Server.
    1. Firstly, replicate the master repository connections i.e. with same naming conventions manually
    2. Go to Dev. Server work repository -> File Tab -> Click on Export work repository (save it in a folder)
    3. After exporting, you can view the xml files in the folders.
    4. Now, Open the Prod. server and make sure you already replicated mas. rep. details.
    5. Now, right click on model and import source model in synonym mode insert_update (select source model from the folder where your xml file located)
    6. Similarily, import again target then Project.
    Now, check. It should work.
    Thank you.

  • How can I move my left over money from my UAE account into USD for my American itunes account?

    How can I move my left over money from my UAE account into USD for my American itunes account?

    How can I go back to my US account then?? I only have .03 aed left..

  • Can I move a Virtual Domain Controller from one host(Win Server 2008 R2) to another (Win Server 2012 R2) ? Are there any issues?

    Can I move a Virtual Domain Controller from one host(Win Server 2008 R2) to another (Win Server 2012 R2) ? Are there any issues?

    I also had this error: "Setup cannot continue. Your computer will now restart, and your previous version of Windows will be restored."
    trying to do a in-place upgrade of a Domain Controller Windows 2008 R2 to Windows 2012 R2.
    The problem was the separated System Reserved Partition. After I removed using this instructions:
    http://jacobackerman.blogspot.com/2012/12/how-to-remove-system-reserved-partition.html
    The upgrade ran ok, and now have my DC as Windows 2012 R2.
    Hope that helps!.

  • How can i move my contacts, mails etc from gmail to icloud?

    How can I move my contacts, mails, etc from gmail account to icloud?

    The following has instructions: https://support.google.com/mail/answer/3008051?hl=en

  • How can I move my Premiere elements 8 from my old pc to my new imac?

    How can I move my Premiere elements 8 from my old pc to my new imac?

    tenfootprints
    Does your imac come with a Windows Mac interface?
    If not, you cannot. There is no Premiere Elements 8 Mac version. And, you cannot install Premiere Elements 8 Windows on
    a Mac computer. As I recall, Premiere Elements 9.0/9.0.1 was the first Premiere Elements version to be offered in Windows and Mac versions.
    Please explain with more details.
    Thanks.
    ATR

  • Can MoveUser move a user's mailbox from an installation of Mail Server 2.X to Messaging Server 3.X?

    Can MoveUser move a user's mailbox from an installation of Mail
    Server 2.X to Messaging Server 3.X?
    <P>
    Yes.
    The 2.x server allows the postmaster to login to a user's account.
    Try running MoveUser as follows:
    MoveUser -u uid -s host -xPostmaster:uid -p password
    -d desthost -a proxyuser -v proxypassword -m mailboxpath
    Notes:
    Mail Server 2.x uses a local database and not an LDAP server
    for account information. The -l option
    specify ldap URL and the associated bindDN password,
    therefore, are not valid when moving from
    Mail Server 2.x to Messaging Server 3.x.
    "Postmaster:" is case sensitive.
    The -a and -v options are for Messaging Server 3.x
    ProxyAuthUser credentials.
    We do NOT allow this login to a 3.x server
    (use PROXYAUTH instead).

    Additionally
    When I type in fasn26p (machine name) the Oracle Application Server Welcome page displays.
    I can get to the Enterprise Manager via the link on the page.
    On the All Programs menu, under Oracle - OraDb10g_home1 I can access the Datbase Control page and login. The line for Database Instance: Orcl is -
    http://fasn26p:1158/em/consol/database/instance/sitemap?event=doloa&....
    One last thought. I installed this with this on my network at home and I now have it disconnected from the network. So no IP address for the adapter and I wonder if that can cause a problem with Apache?
    Sam

  • How can I move Whatsapp or google   photos from the camera roll to a different folder

    How can I move Whatsapp or google   photos from the camera roll to a different folder

    How can I move Whatsapp or google photos from the camera roll to a different folder
    The only way to remove photos from the Camera roll is to delete them. You cannot move them directly from the Camera roll to another album.
    Sync the photos to your computer, remove them from iPhone and resync the photos to your iphone.
    See this -> iOS: Importing personal photos and videos from iOS devices to your computer

  • HT201269 how can i move my photos and videos from my phone to my windows computer?

    how can i move my photos and videos from my phone to my windows computer?

    This will help
    https://discussions.apple.com/message/15032376#15032376

  • How can I move the vertical slider bar from the right to the left of screen

    how can I move the vertical slider bar from the right to the left of screen

    There are also other things that need attention:
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    # Shockwave Flash 10.1 r85
    # Next Generation Java Plug-in 1.6.0_18 for Mozilla browsers
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    Update the [[Java]] plugin to the latest version.
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)

  • Corrupted .docx file. Word 2007. Can't open the document. Tags mismatch. Help?

    The Office Open XML file *.docx cannot be opened because there are problems with the contents.
    Details: The name at the end tag of the element must match the element type in the start tag.
    Location: Part: /word/document.xml, Line: 2, Column: 3487212
    Hmm, I guess I should give some background info and what I've tried so far, right?
    The document is in word 2007, Windows 7. Last night, I was in a hurry, and got a lot of things open. I was opening the document to do a few quick spontaneous revisions, but it was so laggy and I was late for an appointment, so I was feeling panicky
    and frustrated. In hindsight, it probably wasn't the best option to just force shut the PC down cause word stopped responding in the middle of opening the document. Still, while I'm no Sherlock, I knew stopping it while it's in the middle of saving the document
    would bebad, I didn't think stopping it while opening the document (and not really modifying the document at all, at least that was what I thought before), could have drastic consequences! The document's quite
    large, a few hundred words, and about 500 or so pages. It's this really big project I was doing at work, for months now really, and because it's somewhat business confidential in nature, I can't exactly share it freely, or I would've uploaded a copy, sorry.
    Anyway, I woke up this morning and opened it, and the error came up. By the way, the document was saved in a 2TB external hard with a few disk errors in the past, if that helps, even if I'm pretty much sure its not a problem with the hard. The error
    came up... and yeah. I first made a copy, which I've been trying everything on, in case I do end up making things worse. I have no previous versions of it, just a relatively very old backup. Anything less than 80% recovery would set me back weeks with a wage
    cut. The good news is that I was able to open the document in WordPad, managing to recover the first 287 pages (131,543 words), with no errors or data loss, and saved it in a separate file. Apparently, according to information I obtained later, MSWord tends
    to not open at all when it encounters an error, but Wordpad tends to stop reading the rest of the code once it encounters an error. So, naturally, I assumed (so correct me if I'm wrong), that behind a few sentences I might lose due to the error, the rest could
    also be salvageable. I then looked up the problem all over the internet. Read a microsoft article on troubleshooting/recovering corrupted documents (Open & Repair, Draft Mode, Creating Link, Recover text from any file converter, etc). No dice.
    I first saw a similar question on answers.microsoft, and tried to use Tony Jollan's Rebuilder, macros enabled and all. Sadly, no luck.
    I managed to make my first breakthrough when I found out that .docx was just a .zip file, and could be renamed as such, with the document.xml extracted and manually fixed using an XML editor (not that I knew how to do that, but I was desperate and
    willing to learn). So, made another copy, changed extensions, and tried to specifically extract the document.xml. I believe that it is the main body text, right? That is the only thing really necessary for me, since everything I've done so far is entirely
    spartan, with no fancy fonts, formatting, header/footer/notes, media objects, formulas, tables, bullet points, numbered lists, etc. All pure sans-serif text, with some Japanese Kanji thrown in. 500 pages of pure text.
    I then hit a snag, when WinRAR encountered an error on extracting document.xml, stating that "CRC failed in word\document.xml. The file is corrupt". So I tried to fix this using several ZIP repair programs and stuff. Nothing worked. At
    least not so far. Managed to extract an incomplete version of document.xml using WinRAR's 'Keep Broken Files' option when extracting. The extracted
    document.xml came up to 3.31 MB while the original in archive is 7.53 MB. Viewed it in the Windows XML Editor which opened up the text in Internet Explorer, a jumble of text with no line breaks or paragraphs. Still, it actually extracted a few pages less than
    the open-using-Wordpad method tried earlier. So trying to fix the archive again...
    So I decided to give up the manual route for the meantime and focus on readymade solutions. I came across yet another microsoft article, but this one was at least more relevant than the last. It had this auto FixMe thing. I ran it, didn't
    work. Apparently, as I found out later, "This fix will work for one specific tag error where there are equations and graphics in the same paragraph AND Office 2010 SP1 has not been applied."
    Tried several (read: dozens) corrupt Word recovery software, from freeware to pro trials, to varying degrees of effect, although unsuccessful
    in goal. Some failed to read it, saying it was too corrupted for them to handle, the best managed to recover about three-pages-worth less data compared to the Wordpad method. So yeah, anybody with a similar problem, always open it with wordpad first and recover
    what you can. That doesn't mean I'm giving up though.
    So here I am, tearing my hair out in frustration. Whew, I feel like I told you guys my life story. I guess worst case scenario, I report this to my boss, so I personally or from the company, I/we'll hire a team of professionals to deal with it.
    But that's not an ideal scenario. It's gonna be out of my salary either way (the company has a firm policy of 'You reap what you sow'), along with a wage cut for making such an amateurish mistake even with continuous reminders to back it up every two sentences,
    so I'd rather avoid that.
    I'm currently looking to see whether there's a way to recover a previous version of an overwritten document somehow using a third-party software or something. (I didn't have Windows Backup enabled, so no previous version on Windows). So far, no
    autosaved documents on MSWord AutoRecover, even though I have it enabled set to every 3 mins (or maybe I'm just not seeing it since I'm trying to look for it manually?). Or are the temporary files wiped on shutdown? I don't have 'Always save backup copy' option
    enabled on word either.
    So yeah, an auto fix, or a lengthy answer detailing what exactly I should do (from the very very basics), or a link to a site with such info, would be much appreciated. Seriously :D
    Please. Thanks for at least making an effort :)

    When a Word document file is corrupted, then you can try several methods to recover it:
    1. First of all, you can try the recovery function integrated with Microsoft Word, as follows:
    1) On the File menu, click Open.
    2) In the Look in list, click the drive, folder, or Internet location that contains the file that you want to open.
    3) In the folder list, locate and open the folder that contains the file.
    4) Select the file that you want to recover.
    5) Click the arrow next to the Open button, and then click Open and Repair.
    You may find more information about this at:
    http://office.microsoft.com/en-us/word-help/recover-the-text-from-a-damaged-document-HP005189610.aspx (for Word 2003)
    http://support.microsoft.com/kb/893672/en-us (for Word 2007/2010/2013)
    2. If you have multiple corrupt Word documents, then you can use the VBA macro provided in article
    http://support.microsoft.com/kb/893672/en-us so that all the files will be opened in "Open and Repair" option automatically.
    3. There are also free tools from third-parties that can open and read Microsoft Word documents, for example,
    3.1 OpenOffice at http://www.openoffice.org. This is a very famous open source project that is designed to support Office file formats, including Word documents. The software can run under Windows.
    3.2 LibreOffice at http://www.LibreOffice.org. Another free office suite.
    3.3 AbiWord at http://www.abisource.com. This is a cross-platform tool that works under Unix and Windows.
    3.4 Google Drive at https://drive.google.com/ also support to load Word document files.
    Sometimes when Word fails to open your document, these tools may be able to open it successfully. If that is the case, then after the document is opened, you can just save it as a new document which will be error-free.
    4. For docx files, they are actually a group of files compressed in Zip file format. Therefore, sometimes, if the corruption is only caused by the Zip file, then you can use Zip repair tools such as WinRAR at
    http://www.rarlab.com to repair the file, as follows:
    4.1 Assuming the corrupt document is a.docx, then you need to rename it to a.zip
    4.2 Start WinRAR, go to "Tools > Repair Archive" to repair a.zip and generated a fixed file a_fixed.zip.
    4.3 Rename a_fixed.zip back to a_fixed.doc
    4.4 Using Word to open a_fixed.doc.
    There may still be some warnings when opening the fixed file in Word, just let ignore it and Word will try to open and repair the fixed file. If the file can be opened successfully, then you can just save the contents into another error-free file.
    5. If all above methods does not work, then you may try third-party tools such as DataNumen Word Repair at
    http://www.datanumen.com/word-repair/
    I have used it to repair some word documents successfully. It provides a free demo version so that you can try to see if the data you want can be recovered or not.
    Good luck!

Maybe you are looking for

  • Open vi reference conversion from Labview 6 to Labview 2014

    Is there a way that someone can help me convert this VI written in Labview 6.1  so that I can work en EXE in Labview 2014. I succed to open this vi from 6.1 to 2014 but it does not run. The open vi reference those not work in exe program. Someone kno

  • Printing only works from one computer

    I have an Epson Stylus C60 connected to the USB port on my Airport Extreme. There are two computers on the network, a PowerBook G4 and a MacBook Pro. Both computers connect to the network very reliably and have internet access. The problem is that th

  • URGENT *** Hierarchical Tree in Forms 9i *** URGENT

    Hello everybody, for my company I need to build a hierarchical tree item, that will display static data over three levels. Let's say: departments, employees and employee projects. How do I fill the Item? When do I fill the Item? Where do I fill the I

  • Adobe Photoshop CS3 Registration screen blank and unresponsive,

    I just installed Adobe Photoshop CS3 Extended Version, and was eager to use it when I got the registration screen...and it froze. It just blanks out after selecting "Do Not Register" and "Register Later" I don't know how to fix it...can you guys help

  • Audio on Menus not playing

    Hi all, I wonder if anyone can help me. Using Encore on CS4, I created a project with three motion menus. The text was adapted from an Adobe template and the 'motion'' elements (video and audio) were created in Premiere, saved as an MPEG, imported in