Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Programming Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erik Svensson - 15 Nov 2006 14:38 GMT
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
Signature

Student
Chalmers University of Technology, Gothenburg

Klatuu - 15 Nov 2006 15:19 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.