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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF THEN help 1

Status
Not open for further replies.

sblanche

Technical User
Jun 19, 2002
95
US
I am a beginner to VBA. I'm trying to write a statement that would check for a value of 2 in a field called STATUS in a table called QUIT. If it finds 2 it will quit the database. If it finds 1 it does nothing. The statement is on my switchboard.

IF "Quit.Status" = 2 Then
DoCmd.Quit
End IF

I've looked all through my manuals and getting frustrated since this should be easy. Any help would be appreciated.
SB
 
Hi

There is not enough information to answer accurately,

if the table has been opened in a recordset

If Rs!Status = 2 Then
docmd.quit
End if

If the data from the table has been stored into a variable then

If MyVariable = 2 Then
..etc

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Try

IF [Status] = 2 Then
DoCmd.Quit
End IF



Hope this helps
Hymn
 
Sorry I did not give enough information. I'm trying to boot everyone out of my db. I'm using "ontimer" on the switchboard for this statement. It's going to check the table QUIT to see if I have enterred a "2". If it finds a "2" it's going to "quit" the db. The table has not been opened in a recordset or stored in a variable. It's just a tiny table that I will enter either a 1 or 2. Thank you--
 
Take a look at the DLookup function.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Here is the code you need

Code:
dim db as Database
dim rsQuit as Recordset

set db = Currentdb
set rsQuit =db.Openrecordset("Quit",dbOpenSnapshot)

'This a assuming you have a record in the QUIT table
with rsQuit
    .MoveFirst
    If !Status=2 Then
        Docmd.Quit
    Else
     rsQuit.Close
     set db=Nothing
    End If
end with
 
A Dlookup would be better.

Code:
Dim intExit as Integer

intExit=Dlookup("Status","QUIT")

If intExit=2 then Docmd.Quit
 
Excellent--Both answers work great. You have made a frustrating day (really 3 days) look a little brighter. Thank you!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top