1.7K Posts

January 14th, 2005 12:00

How is your database structured (Rows, Columns, Field Names). Will you always have 58, or could this change?

Let me know and I'll see if I can help.

2 Posts

January 14th, 2005 15:00

Database can change depending on needs. This one is structured as such:

Name  Address  City  SS#  DOB  DOH  Income (there are more columns but I don't need this info now)

There are 50 rows of data.  I named the above data range "census"  The form I want to fill in is on another sheet in the workbook, the form is named "form".  I need to fill in the blank info in the form from the database (the above info), calculate, the print the form, repeat to the end of the 50+ names.  Would be nice to have a pause function or a Print (Y/N) function in case of errors.  I have recorded a macro that will fill in the form from the first row of data, tried a count statement with a next statement but to no avail.  I had a macro written in xlm but could not translate it to vbe.

Thanks for any help or guidance you can provide!

1.7K Posts

January 14th, 2005 15:00

So I understand you correctly, you want to take one record at a time from the census range, copy the information to another worksheet, print the one record's information on the form worksheet, then clear the information, copy the next record from the census range, and keep repeating until the last record.

I would need to see the form worksheet, as it is necessary to know what cells the information will be placed into.

1.7K Posts

January 16th, 2005 17:00

I've sent you the Excel file. The code will find the Census range, determine how many records (rows) are in the range, then loop through each one, pausing to ask if you want to preview the form. The code is available by pressing ALT-F11 to open the VBA window. I've posted it below. Hope this works well for you.

Sub FillValues()
    Dim intRows As Integer
    Dim i As Integer
    Dim x As Integer

On Error GoTo HandleErr
    Application.Goto Reference:="Census"
    Selection.End(xlDown).Select
    intRows = Selection.Row + 1 'Determine the total rows in range
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    x = Selection.Row  'Determine the first row number
    Sheets("EE Form").Select
    i = x
    Do Until i = intRows    'Loop through the range, finding values
        Range("C5").Select
        ActiveCell.Formula = "=Census!B" & i
        Range("I5").Select
        ActiveCell.Formula = "=Census!G" & i
        Range("C7").Select
        ActiveCell.Formula = "=Census!C" & i
        Range("I6").Select
        ActiveCell.Formula = "=Census!I" & i
        Range("I7").Select
        ActiveCell.Formula = "=Census!H" & i
        Range("C9").Select
        ActiveCell.Formula = "=Census!D" & i
        Range("C10").Select
        ActiveCell.Formula = "=Census!E" & i
        Range("C12").Select
        ActiveCell.Formula = "=Census!F" & i
        i = i + 1
        If MsgBox("Preview worksheet for " & Range("C5").Value & "?", vbYesNo + vbQuestion) = vbYes Then
            ActiveWindow.SelectedSheets.PrintPreview
        End If
    Loop

    MsgBox "Finished", vbInformation
   

ExitHere:
    Exit Sub

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
' Automatic error handler last updated at 01-15-2005 11:00:14   'ErrorHandler:$$D=01-15-2005    'ErrorHandler:$$T=11:00:14
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Module1.FillValues" 'ErrorHandler:$$N=Module1.FillValues
    End Select
    Resume ExitHere
' End Error handling block.
End Sub

No Events found!

Top