Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code not executing

Status
Not open for further replies.

bmc1234

Programmer
Jul 21, 2005
50
US
I have vba code that runs when a form opens. It checks how many records are included in the form. If there is 0, then is does something specific. The problem is that the code isn't executing. There is the code:
Code:
Private Sub Form_Open(Cancel As Integer)
MsgBox Me.RecordsetClone.RecordCount
If Me.RecordsetClone.RecordCount < 1 Then
    MsgBox "hi"
    Me.RemovedPN.SetFocus
    Me.buttonnew.Visible = False
    Me.ButtonClose.Visible = True
    If IsFormLoaded("repairdata") Then
        Me.RepairDataID = Forms!repairdata.RepairID
    End If
End If
End Sub
When there are 0 records, it displays the "hi" message box so I know its going into the If statement, but doesn't seem to execute the code after that. There are two buttons that are overlapped. It is supposed to hide one button and unhide another.
 
Choose the Load event procedure instead of the Open one.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya bmc1234 . . . . .

Don't know the size of the recordset your dealing with but larger recordsets take time to load. Try [blue]PHV's[/blue] suggestion, and if you still have trouble try the following in the [blue]OnLoad[/blue] event:
Code:
[blue]Private Sub Form_Open(Cancel As Integer)
   Dim rst As DAO.Recordset
   
   Set rst = Me.RecordsetClone
   rst.MoveLast
   DoEvents [green]'Allow time to load[/green]
   
   MsgBox rst.RecordCount
   
   If rst.RecordCount < 1 Then
       MsgBox "hi"
       Me!RemovedPN.SetFocus
       Me!buttonnew.Visible = False
       Me!ButtonClose.Visible = True
         
      If IsFormLoaded("repairdata") Then
          Me!RepairDataID = Forms!repairdata.RepairID
      End If
   End If

   Set Rst = Nothing
End Sub[/blue]
The code requires [purple]Microsoft DAO 3.6 Object Library[/purple] to run. To [blue]check/install[/blue] the library, in any code window click [blue]Tools[/blue] - [blue]References...[/blue] In the listing find the library and [blue]make sure its checked.[/blue] Then using the up arrow, [purple]push it up as high in priority as it will go[/purple]. Click OK.

Calvin.gif
See Ya! . . . . . .
 
Did u try a Msgbox after "Me.ButtonClose.Visible = True"?
What about IsFormLoaded function..its not a built in function is it? Is it executing properly?
 
I tried what theaceman said and it didn't work.

I did put a msgbox at other points in the code and they execute, so it seems like skipping specific lines, or executing them and just not giving me what I want for some reason.
The isformloaded function works fine. I've been using it for a while, so that shouldn't be the problem.
 
bmc1234 . . . . .

I didn't read your post origination properly. You said you get the Msgbox "hi" but not the rest. So you are detecting empty recordsets!.

Are you saying [blue]ButtonClose[/blue] doesn't become visible and/or [blue]RepairID[/blue] is not being transfered to the form where the code is running?

In either case, check the [blue]Name[/blue] property of the controls . . . [purple]these are the names you should be using in VBA.[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top