View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Calligra[_2_] Calligra[_2_] is offline
external usenet poster
 
Posts: 17
Default Message box causing error in code



Ed, Yes I did. Below is the missing portion of the code. Sorry about
that.

Private Sub UserForm_Initialize()
Dim fValid As Boolean
Dim Counter As Integer
Dim Ctrl As Control
Dim i As Integer
Dim iCount As Integer
Dim itemp1 As Integer
Dim itemp2 As Integer
Dim itemp3 As Integer
Dim itemp4 As Integer
Dim itemp5 As Integer
Dim Book As Workbook
Dim iMinCellRow As Integer
Dim iMaxCellRow As Integer
Dim iCellValue As String
Dim NameCounter As Integer
Dim ans As String


Set Book = ActiveWorkbook
Application.ScreenUpdating = False
'Open workbook
Workbooks.Open Filename:=ThisWorkbook.Path & "\Data Doc.xls"
Book.Activate
Application.ScreenUpdating = True
' Find last used row
With Workbooks("Data Doc.xls").Sheets("Sheet1")
Counter = 1
iCellValue = .Cells(Counter, 2).Value
If iCellValue < "" Then
Do
Counter = Counter + 1
Loop While .Cells(Counter, 2).Value < ""
End If
Counter = Counter - 1
If ((.Cells(Counter, 1).Value < Application.UserName) And
(.Cells(Counter, 2).Value < Book.Name) And (.Cells(Counter, 1).Value <
"")) Then
' if form is empty then
With Book.frmLogIn
.TextBox1.Text = Application.UserName
.TextBox2.Text = Now
.TextBox1.SetFocus
OptionButton23.Enabled = False
OptionButton24.Enabled = False
TextBox3.Enabled = False
End With
Else
' Read the values and place into form
For NameCounter = Counter To 2 Step -1
If ((.Cells(NameCounter, 1).Value < "") And
((NameCounter) < 2)) Then
TextBox1.Text = .Cells(Counter, 1).Value
End If
Next NameCounter
If TextBox1.Text = "" Then
TextBox1.Text = Application.UserName
End If

TextBox2.Text = .Cells(Counter, 3).Value
TxtVersion.Text = .Cells(Counter, 13).Value
TextBox4.Text = .Cells(Counter, 14).Value
TextBox5.Text = .Cells(Counter, 9).Value
TextBox6.Text = .Cells(Counter, 10).Value

For iCount = 1 To 31
Set Ctrl = Controls("OptionButton" & iCount)
If iCount < 8 Then
If Ctrl.Caption = CStr(.Cells(Counter, 6).Value)
Then
Ctrl.Value = True
End If
ElseIf ((iCount 7) And (iCount < 15)) Then
If ((Ctrl.Caption = .Cells(Counter, 7).Value) And
(iCount < 14)) Then
Ctrl.Value = True
ElseIf ((TextBox3 = .Cells(Counter, 7).Value) And
(iCount = 14)) Then
Ctrl.Value = True
TextBox3.Value = .Cells(Counter, 7).Value
End If
ElseIf ((iCount 14) And (iCount < 22)) Then
If ((Ctrl.Caption = .Cells(Counter, 8).Value) And
(iCount < 21)) Then
Ctrl.Value = True
ElseIf ((OptionButton23.Caption = .Cells(Counter,
8).Value) And (iCount = 21)) Then
Ctrl.Value = True
OptionButton23.Value = True
ElseIf ((OptionButton24.Caption = .Cells(Counter,
8).Value) And (iCount = 21)) Then
Ctrl.Value = True
OptionButton24.Value = True
End If
ElseIf ((iCount 24) And (iCount < 28)) Then
If Ctrl.Caption = .Cells(Counter, 11).Value Then
Ctrl.Value = True
End If
Else
If Ctrl.Caption = .Cells(Counter, 12).Value Then
Ctrl.Value = True
End If
End If
Next iCount
End If
End With
'Close workbook
Workbooks("Data Doc.xls").Close SaveChanges:=True

frmLogIn.Show
ans = MsgBox("Is the information contained within this form still
correct?", vbYesNo)
If ans = vbYes Then
Set Book = Nothing
Call CmdOK_Click
End If
End Sub

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!