Programming Form

E

Erik Svensson

Hi
I have a form with a subform (shown as a list) and I am trying to make a
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
...... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 
K

Klatuu

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


Erik Svensson said:
Hi
I have a form with a subform (shown as a list) and I am trying to make a
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
..... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 
E

Erik Svensson

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

--
Student
Chalmers University of Technology, Gothenburg


Klatuu said:
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


Erik Svensson said:
Hi
I have a form with a subform (shown as a list) and I am trying to make a
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
..... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 
K

Klatuu

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.

Erik Svensson said:
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

--
Student
Chalmers University of Technology, Gothenburg


Klatuu said:
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


Erik Svensson said:
Hi
I have a form with a subform (shown as a list) and I am trying to make a
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
..... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 
E

Erik Svensson

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
--
Student
Chalmers University of Technology, Gothenburg


Klatuu said:
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.

Erik Svensson said:
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

--
Student
Chalmers University of Technology, Gothenburg


Klatuu said:
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
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
..... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 
K

Klatuu

Great, glad you got it working.

Erik Svensson said:
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
--
Student
Chalmers University of Technology, Gothenburg


Klatuu said:
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.

Erik Svensson said:
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

--
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
button that takes the number in the active record in the subform and put it
in the textbox with the lowest number available. I have created 9 textboxes
where the first is named Module_entry and the rest is named Module1, Module2
..... I am using the Module_entry text box to retrieve the information from
the subform and then I want the button to take the active record and place
that number in the lowest Module# box that is available. This is the code I
have for the moment and it does not work. The error say "Compile error: Else
without IF"

Private Sub Command37_Click()
On Error GoTo Err_Command37_Click


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
End If

Me.Module_entry = Null


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub

BR/Erik Svensson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top