Not able DELETE / INSERT in Remote Database (1 Viewer)

ria_arora

Registered User.
Local time
Today, 20:57
Joined
Jan 22, 2011
Messages
56
Dear All,

I'm executing below simple SQL to delete the data from Remote Database but somehow it's not deleting the data.

Code:
        strDeleteSQL = "DELETE FROM " & sTableName
        gsCnPDatabase.Execute (strDeleteSQL)

Code for Remote database

Code:
Option Compare Database
Global gsCnPDatabase As DAO.Database            'CnP Secured MS Access Database
Global gsCnPDatabaseOpened As Boolean   'Assign Value TRUE once MS Access DB connection is opened
 
'Function is used to connect Secured ACCESS Database and extract CnP database information and assign True value to global variable
Public Function ConnectCnpDatabase() As Boolean
    Dim sCnPDatabaseName As String
    Dim sDatabasePassword As String
    
    On Error GoTo ErrConnectDB
    ConnectCnpDatabase = False
    sCnPDatabaseName = ExtractDatabaseDetails.GetDatabasePath(gsCnPDatabaseID) & "\" & ExtractDatabaseDetails.GetDatabaseName(gsCnPDatabaseID)
    sCnPDatabasePassword = GetDatabasePassword(gsCnPDatabaseID)
    
    ' Create Microsoft Jet Workspace object.
    Set gCurWS = DBEngine.Workspaces(0)
    Set gsCnPDatabase = gCurWS.OpenDatabase(sCnPDatabaseName, False, False, "MS Access;PWD=" & sCnPDatabasePassword)
    ConnectCnpDatabase = True
    gsCnPDatabaseOpened = True  'Assign TRUE once MS Access Secured Database is Initialised
    
    Exit Function
ErrConnectDB:
    gsDBErr = Err.Description
End Function
'Disconnect Secured Access Database
Public Sub DisconnectCnPDatabase()
    If gsCnPDatabaseOpened = True Then  'If MS Access Secured Database is opened
        gsCnPDatabase.Close
        gsCnPDatabaseOpened = False
    End If
    Set gsCnPDatabase = Nothing
End Sub[\code]
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:57
Joined
Jul 9, 2003
Messages
16,404
Dear All,

I'm executing below simple SQL to delete the data from Remote Database but somehow it's not deleting the data.

Code:
        strDeleteSQL = "DELETE FROM " & sTableName
        gsCnPDatabase.Execute (strDeleteSQL)

Code for Remote database

Code:
Option Compare Database
Global gsCnPDatabase As DAO.Database            'CnP Secured MS Access Database
Global gsCnPDatabaseOpened As Boolean   'Assign Value TRUE once MS Access DB connection is opened
 
'Function is used to connect Secured ACCESS Database and extract CnP database information and assign True value to global variable
Public Function ConnectCnpDatabase() As Boolean
    Dim sCnPDatabaseName As String
    Dim sDatabasePassword As String
    
    On Error GoTo ErrConnectDB
    ConnectCnpDatabase = False
    sCnPDatabaseName = ExtractDatabaseDetails.GetDatabasePath(gsCnPDatabaseID) & "\" & ExtractDatabaseDetails.GetDatabaseName(gsCnPDatabaseID)
    sCnPDatabasePassword = GetDatabasePassword(gsCnPDatabaseID)
    
    ' Create Microsoft Jet Workspace object.
    Set gCurWS = DBEngine.Workspaces(0)
    Set gsCnPDatabase = gCurWS.OpenDatabase(sCnPDatabaseName, False, False, "MS Access;PWD=" & sCnPDatabasePassword)
    ConnectCnpDatabase = True
    gsCnPDatabaseOpened = True  'Assign TRUE once MS Access Secured Database is Initialised
    
    Exit Function
ErrConnectDB:
    gsDBErr = Err.Description
End Function
'Disconnect Secured Access Database
Public Sub DisconnectCnPDatabase()
    If gsCnPDatabaseOpened = True Then  'If MS Access Secured Database is opened
        gsCnPDatabase.Close
        gsCnPDatabaseOpened = False
    End If
    Set gsCnPDatabase = Nothing
End Sub[\code][/QUOTE]

I can't see where you are executing the SQL statement?
 

ria_arora

Registered User.
Local time
Today, 20:57
Joined
Jan 22, 2011
Messages
56
It's working fine. Not sure what happened. I did not change the code, next day it start working,

Thanks for the help
 

ria_arora

Registered User.
Local time
Today, 20:57
Joined
Jan 22, 2011
Messages
56
Yes Khalid after all it's Microsoft product. Some time need to restart the PC.

:)
 

boblarson

Smeghead
Local time
Today, 05:57
Joined
Jan 12, 2001
Messages
32,059
Just a quick word for you (based on your global variables).

The keyword Global is only around for backwards compatibility. You should use

Public YourVariableName As VariableType

when declaring global variables. That is the more current method. There is no telling if they will drop Global from VBA at any point so it is a good idea to move to that as you do new programming.
 

smig

Registered User.
Local time
Today, 15:57
Joined
Nov 25, 2009
Messages
2,209
shouldn't it be:
strDeleteSQL = "DELETE * FROM " & sTableName
 

ria_arora

Registered User.
Local time
Today, 20:57
Joined
Jan 22, 2011
Messages
56
smig

You can use *, but without * also works fine.

It's like when you want to count number of records instead of
SELECT COUNT(*) FROM TableName

You can write
SELECT COUNT('x') FROM TableName

and that will be faster then *.
 

Users who are viewing this thread

Top Bottom