0

thanks in advance.

I've come across a problem that I'm sure is going to be really simple to fix however I can't seem to see where I'm going wrong. The Idea of this piece of code is to run a check on a form to ensure that all fields are filled in before allowing it to be added to the database:

Dim aSCt As Integer, blankchk As Range, eRmSg As String, DISP As Integer, SectDisp As Integer
eRmSg = "Please ensure that all assesments have been completed and where not applicable the N/A option is selected." & vbNewLine & "The following fields need to be filled in:" & vbNewLine & vbNewLine
aSCt = 0
DISP = 0
SectDisp = 0
Set blankchk = Range("H9")
        Do While aSCt < 14
            If IsEmpty(blankchk) Then
                'if first blank in this section then add section title
                If SectDisp = 0 Then
                    eRmSg = eRmSg & "SECTION A - scope:" & vbNewLine
                    SectDisp = 1
                End If
                'add area to list
                eRmSg = eRmSg & "    " & blankchk.Offset(0, -6).Value & vbNewLine
                'Tell error message to display at end
                DISP = 1
            End If
            'choose next cell down and update counter
            blankchk = blankchk.Offset(1, 0)
            aSCt = aSCt + 1
        Loop

This seems fine to me.. However I'm having a problem with adding "blankchk.Offset(0, -6).Value" to the string. For some reason it is taking Range("H9").value (the original 'blankchk' designation) every time. So the output will show:

Section A -scope
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name
Rig Name

etc.

Why is it doing this? Surely the offset(1,0) changes this reference???

Please help

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
matt
  • 15
  • 1
  • 4

1 Answers1

1

Simply change

blankchk = blankchk.Offset(1, 0)

to

Set blankchk = blankchk.Offset(1, 0)

:)

Bernard Saucier
  • 2,240
  • 1
  • 19
  • 28