UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> If Then Elseif Question, Access 2007    
 
   
jysharp2003@yaho...
post Apr 15 2019, 04:59 AM
Post#1



Posts: 20
Joined: 23-January 19



Hi,
This seems basic but can't seem to configure it or find the example online.
I have a form that checks tables and results in appropriate form to open up.
Data conditions are:
If rstrial exceeds count of 60 then frmtrial (I will alert users trial expired and to process payment)
If rs is not 0 then close frmPremain and open the append form
If all above checks out then close the frmPremain and open frmmain.
Below snippet results in the frmPremain remaining open if I setup table conditions to result in opening the frmmain.
Thanks for looking at this and providing some solution.
Jerry


Set rs = db.OpenRecordset("SELECT COUNT(ID) FROM append_schedule_full")
Set rstrial = db.OpenRecordset("SELECT Count(trial_pre.short_date) AS CountOfshort_date FROM trial_pre")
If rstrial(0) > 60 Then
DoCmd.Close acForm, "frmPremain"
DoCmd.OpenForm "frmtrial"

ElseIf rs(0) <> 0 Then
DoCmd.Close acForm, "frmPremain"
DoCmd.OpenForm "append_schedule_full"
'End If

DoCmd.Close acForm, "frmPremain"
DoCmd.OpenForm "frmmain"
End If
Go to the top of the page
 
DanielPineault
post Apr 15 2019, 05:11 AM
Post#2


UtterAccess VIP
Posts: 6,503
Joined: 30-June 11



You might try something more along the lines of
CODE
    Dim bTrial                As Boolean
     Dim bMain                 As Boolean

     Set rs = db.OpenRecordset("SELECT COUNT(ID) FROM append_schedule_full", dbOpenSnapshot)
     rs.MoveLast
     Set rstrial = db.OpenRecordset("SELECT Count(trial_pre.short_date) AS CountOfshort_date FROM trial_pre", dbOpenSnapshot)
     rstrial.MoveLast

     If rstrial > 60 Then
         bTrial = True
     End If
     If rs > 0 Then
         bMain = True
         DoCmd.OpenForm "append_schedule_full"
     End If

     If bTrial And bMain Then
         DoCmd.Close acForm, "frmPremain"
         DoCmd.OpenForm "frmmain"
     End If

When using OpenRecordset you should use MoveLast to ensure you get the proper record count. Also, if all you are after is the count, you might want to consider using DCount instead.

--------------------
Daniel Pineault (2010-2018 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
cheekybuddha
post Apr 15 2019, 05:17 AM
Post#3


UtterAccess VIP
Posts: 11,019
Joined: 6-December 03
From: Telegraph Hill


It looks as if you wish to close frmPremain whatever the circumstance.

Is this code called from frmPremain?

Try something like:
CODE
  Dim strFormToOpen As String

  Select Case True
  Case DCount("short_date", "trial_pre") > 60
    strFormToOpen = "frmtrial"
  Case DCount("*", "append_schedule_full") <> 0
    strFormToOpen = "append_schedule_full"
  Case Else
    strFormToOpen = "frmmain"
  End Select

  DoCmd.OpenForm strFormToOpen
  DoCmd.Close acForm, "frmPremain"


hth,

d


--------------------


Regards,

David Marten
Go to the top of the page
 
jysharp2003@yaho...
post Apr 15 2019, 06:48 AM
Post#4



Posts: 20
Joined: 23-January 19



Thanks. I totally love learning new stuff.
Inserting the code at my form though does result in below error. Checked for obvious issues but looks all in order.
Can you see anything? Hovering over the btrial and bmain they show False so should have a close of frmPremain and open the frmmain. FYI I added the DoCmd.OpenForm "frmtrial" as it seemed missing.
Thanks again.

Help button shows this
Invalid argument. (Error 3001)
You tried to perform an operation that involves a routine in a DLL, and one of the arguments to the routine is invalid. Check your entry to make sure you have specified the correct arguments, and then try the operation again.
This error also occurs when you attempt to use mutually exclusive constants in an argument to a method, such as specifying both dbConsistent and dbInconsistent in the options argument to the OpenRecordset method.
© 2007 Microsoft Corporation. All rights reserved.

Attached File(s)
Attached File  followonerror.jpg ( 101.6K )Number of downloads: 8
 
Go to the top of the page
 
jysharp2003@yaho...
post Apr 15 2019, 07:04 AM
Post#5



Posts: 20
Joined: 23-January 19



Success with the String method.
Thank you very much! Thank goodness I didn't have to share my full VBA, messy.
I appreciate your great sharing of your knowledge.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th April 2019 - 07:22 PM