Public Function needs to make a decision (1 Viewer)

Waxmann

New member
Local time
Today, 16:49
Joined
Aug 18, 2020
Messages
26
I have a table called tblConfig. I need to make this function (Public Function ExportBatch()) to make a decision based on whether the tblConfig.UseServer is true or false. If True it should run Export-FORM. if False it should run Export-FORMServer. I'm new and not sure what I'm doing wrong. Please help.

Public Function ExportBatch()

Dim strServer As String
strReport = DLookup("UseServer", "tblConfig")

If strReport.value = T

DoCmd.RunSavedImportExport "Export-FORM"
Dim myPath As String
myPath = "C:\CCBatch\Rename.bat"
Call Shell(myPath, 1)
Else
DoCmd.RunSavedImportExport "Export-FORMServer"
Dim myPath As String
myPath = "C:\Program FIles (x86)\Comcash 8.0\Rename.bat"
Call Shell(myPath, 1)
End If
End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:49
Joined
Sep 21, 2011
Messages
14,231
To start with, use code tags so you keep any indentation.
Make sure you have
Code:
Option Compare Database
Option Explicit
at the top of every module.

You have to add those you have already created, but Set Require Variable Declaration in VBA Tools/Options for future modules, will give you Option Explicit. That way anything not declared like your strReport will be highlighted.

Code:
Public Function ExportBatch()

    Dim blnReport As Boolean
    Dim myPath As String

    blnReport = DLookup("UseServer", "tblConfig")

    If blnReport Then
        DoCmd.RunSavedImportExport "Export-FORM"
        myPath = "C:\CCBatch\Rename.bat"
    Else
        DoCmd.RunSavedImportExport "Export-FORMServer"
        myPath = "C:\Program FIles (x86)\Comcash 8.0\Rename.bat"
    End If
    Call Shell(myPath, 1)

End Function

That should get you started.
HTH
 

Waxmann

New member
Local time
Today, 16:49
Joined
Aug 18, 2020
Messages
26
To start with, use code tags so you keep any indentation.
Make sure you have
Code:
Option Compare Database
Option Explicit
at the top of every module.

You have to add those you have already created, but Set Require Variable Declaration in VBA Tools/Options for future modules, will give you Option Explicit. That way anything not declared like your strReport will be highlighted.

Code:
Public Function ExportBatch()

    Dim blnReport As Boolean
    Dim myPath As String

    blnReport = DLookup("UseServer", "tblConfig")

    If blnReport Then
        DoCmd.RunSavedImportExport "Export-FORM"
        myPath = "C:\CCBatch\Rename.bat"
    Else
        DoCmd.RunSavedImportExport "Export-FORMServer"
        myPath = "C:\Program FIles (x86)\Comcash 8.0\Rename.bat"
    End If
    Call Shell(myPath, 1)

End Function

That should get you started.
HTH
Thanks for the help, It now works!
 

Waxmann

New member
Local time
Today, 16:49
Joined
Aug 18, 2020
Messages
26
Where do I add;

Option Compare Database
Option Explicit

And can you expand on why I need it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:49
Joined
Sep 21, 2011
Messages
14,231
If you do not have Option Explicit, then you can write any old thing, as you did, with strServer declared and strReport not. :(
You need to Dim the required variables. option Explicit would tell you strReport was not declared.
Plus you used a string for a boolean check?

Google for Option Compare Database

As always, I advise to walk through code (line by line if needed) and see what is produced, NOT what you think is produced.

Option Compare Database
Option Explicit
should be at the top of every module you have. At least Option Explciit, if you think the Database option does not apply to you.
 

Users who are viewing this thread

Top Bottom