Quick Help with VBA If (match 2 Fields) Then

SmartCarFun

Registered User.
Local time
Today, 02:22
Joined
Feb 17, 2012
Messages
25
Hi,
I'm guessing this is rather simple but it's not working as I thought it might...

I have a local table and a linked table, both have only one record and I want to verify one table has a greater value than the other before allowing the user entry... so it looks like this.....

Code:
Private Sub Form_Open(Cancel As Integer)
If [ReleaseNo] >= [tblVersionServer].[VersionNumber] Then
    DoCmd.Close acForm, "DBopen1"
    DoCmd.OpenForm "DBopen2"
 
 Else
    MsgBox "Incorrect version number, please update application", vbInformation, "Quiting Database"
    DoCmd.Quit
End If
End Sub

The first issue is [ReleaseNo] >= [tblVersionServer].[VersionNumber] is wrong...

Next I would love to put a 5 second limit on msgbox - FORCING docmd.quit so a user doesn't leave the application open and walk away or go home.....

I tried Application.Wait Now + TimeValue("00:00:5") but that was a feeble attempt....

Thanks in advance for your help

DM
 
The first point would be you need to actually look up those values. They don't exist in VBA, you have to get at the somehow. The DLookup function is the simplest way:

If DLookup("ReleaseNo", Me.RecordSource) >= DLookup("VersionNumber", "tblVersionServer") Then

(I don't know the name of the table the field ReleaseNo is in so I've used Me.RecordSource. That would be better changed to "TheTablesName".)

The second point: No you can't put the message box on a timer. You'd have to create your own message form with a five second timer that closes itself on the timer event and open that as a dialog.
 
Many thanks, here is my code for those interested in future...

Looks at a checkbox to see if application is in maintenance:

Code:
Private Sub Form_Open(Cancel As Integer)
If (Me.LogOutAllUsers) = 0 Then
    DoCmd.Close acForm, "DBopen1_Maintenance"
    DoCmd.OpenForm "DBopen2_Version"
 
 Else
    CreateObject("WScript.Shell").PopUp "Application closed for maintenance - Try back in 5 minutes!", 3, "Alert! - Quitting Database"
    DoCmd.Quit
End If
End Sub


Next form then matches a local and linked table to verify version number is up to date....

Code:
Private Sub Form_Open(Cancel As Integer)
If DLookup("ReleaseNo", Me.RecordSource) >= DLookup("GKVersion", "tblVersionServer") Then
    DoCmd.Close acForm, "DBopen2_Version"
     DoCmd.OpenForm "NAV_GK_COLLECTORS"
 
 Else
    CreateObject("WScript.Shell").PopUp "Incorrect version number, please install latest application", 3, "Alert! - Quitting Database"
    DoCmd.Quit
End If
End Sub

This code opens a message box and closes it after 3 seconds...
Code:
CreateObject("WScript.Shell").PopUp "Incorrect version number, please install latest application", 3, "Alert! - Quitting Database"

Thanks to VilaRestal for your help....

DM
 
CreateObject("WScript.Shell").PopUp

That's a handy trick.
 

Users who are viewing this thread

Back
Top Bottom