
Signature
Student
Chalmers University of Technology, Gothenburg
The problem with your code is you are mixing single line If statments on
multiple lines. The first line
> If Module1 = "" Then Module_entry = Module1
is a complete statment. The compile sees the first line with ElseIf as the
beginning of a new statment. This is one of the reasons I preach that single
line If statments are a bad habit.
The correct coding should be:
If Module1 = "" Then
Module_entry = Module1
ElseIf Module2 = "" Then
Module_entry = Module2
ElseIf Module3 = "" Then
Module_entry = Module3
ElseIf Module4 = "" Then
Module_entry = Module4
ElseIf Module5 = "" Then
Module_entry = Module5
ElseIf Module6 = "" Then
Module_entry = Module6
End If
Note also, that the default value for a form control, unless otherwise
specificed, is Null. Checking for "" may not return accurate results. It it
is possible it could be either Null or "", the following code will allow for
that.
Dim lngCtr As Long
Dim ctl As Control
For lngCtr = 1 To 6
Set ctl = Me.Controls("Module" & Cstr(lngCtr))
If Len(Trim(Nz(ctl, ""))) = 0 Then
Me.Module_entry = ctl
Exit For
End If
> Hi
> I have a form with a subform (shown as a list) and I am trying to make a
[quoted text clipped - 36 lines]
>
> BR/Erik Svensson
Erik Svensson - 15 Nov 2006 15:35 GMT
Hi
Just as you know I don't have any real programming experience but I am
learning this right now. I am not really sure of how to use the code as you
posted and when I used it like below it give me the "compile error: For
without next". Could you help me?
Private Sub Command37_Click()
On Error GoTo Err_Command37_Click
Dim lngCtr As Long
Dim ctl As Control
Me.Module_entry = Me![CUSTOM quote module search form
subform]![Pseudo_Number]
If Module1 = "" Then
Module_entry = Module1
ElseIf Module2 = "" Then
Module_entry = Module2
ElseIf Module3 = "" Then
Module_entry = Module3
ElseIf Module4 = "" Then
Module_entry = Module4
ElseIf Module5 = "" Then
Module_entry = Module5
ElseIf Module6 = "" Then
Module_entry = Module6
ElseIf Module7 = "" Then
Module_entry = Module7
ElseIf Module8 = "" Then
Module_entry = Module8
End If
For lngCtr = 1 To 8
Set ctl = Me.Controls("Module" & CStr(lngCtr))
If Len(Trim(Nz(ctl, ""))) = 0 Then
Me.Module_entry = ctl
Exit For
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_Command37_Click:
Exit Sub
Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click
End Sub
Sincerely
Erik Svensson

Signature
Student
Chalmers University of Technology, Gothenburg
> The problem with your code is you are mixing single line If statments on
> multiple lines. The first line
[quoted text clipped - 74 lines]
> >
> > BR/Erik Svensson
Klatuu - 15 Nov 2006 16:16 GMT
Sorry about that, I must have left it off. It should be:
For lngCtr = 1 To 8
Set ctl = Me.Controls("Module" & CStr(lngCtr))
If Len(Trim(Nz(ctl, ""))) = 0 Then
Me.Module_entry = ctl
Exit For
End If
Next lngCtr
Now, if you use this, you don't need the longer If, ElseIf, etc. It is just
a different way to do the same thing.
> Hi
> Just as you know I don't have any real programming experience but I am
[quoted text clipped - 128 lines]
> > >
> > > BR/Erik Svensson
Erik Svensson - 15 Nov 2006 16:32 GMT
Hi
This didn't work imideately but when I changed your line Me.Module_entry =
ctl to ctl = Me.Module_entry it works perfectly. So the complete code should
be:
For lngCtr = 1 To 8
Set ctl = Me.Controls("Module" & CStr(lngCtr))
If Len(Trim(Nz(ctl, ""))) = 0 Then
ctl = Me.Module_entry
Exit For
End If
Next lngCtr
Thank you
//Erik

Signature
Student
Chalmers University of Technology, Gothenburg
> Sorry about that, I must have left it off. It should be:
> For lngCtr = 1 To 8
[quoted text clipped - 140 lines]
> > > >
> > > > BR/Erik Svensson
Klatuu - 15 Nov 2006 17:01 GMT
Great, glad you got it working.
> Hi
> This didn't work imideately but when I changed your line Me.Module_entry =
[quoted text clipped - 156 lines]
> > > > >
> > > > > BR/Erik Svensson