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

what it means: Method 'connection' of object' _currentproject' failed

Status
Not open for further replies.

sallyGals

Programmer
Feb 1, 2006
35
DE
i have develop a system by using my pc, then i need to install this system in the server.But i face problem when i put in the server. In the beginning, the function that i done can not work, after i add in the EYEDOG.OCX file, it can work already. But now i face another problem.

i had use a invisible textbox to do the connection.This is the code below:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim intresponse As Integer

If Me.optCheckNew = True Then
intresponse = MsgBox("are you sure you want to save this record?", vbOKCancel)
If intresponse = vbOK Then
Set objConn = Application.CurrentProject.Connection
Set objRecSrc = CreateObject("ADODB.Recordset")

objRecSrc.Open "tblLotCreated", objConn _
, adOpenStatic _
, adLockOptimistic _
, adCmdTable

If objRecSrc.Supports(adAddNew) Then
objRecSrc.AddNew
objRecSrc!DateCreated = Me.fakeDateCreated
objRecSrc!ProductNo = Me.fakeProductNo
objRecSrc!LotID = Me.fakeLotID
objRecSrc!QtyCreated = Me.fakeQtyCreated
objRecSrc!Shift = Me.fakeShift
objRecSrc.Update

Me.frmLotCreated1_List.Requery
Me.Requery
End If
Exit Sub
End If

Else
Me.optCheckNew = False
MsgBox ("Please click new before insert a new record")
End If

Me.cmdNew.SetFocus


Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click


End Sub


i think this code is no problem because it can work in my pc. But when i open in the server in another pc, it show this error:
Method 'connection' of object' _currentproject' failed.


what i can do?
thanks for help.
 
I don't know that error and since nobody else has answered yet, if you check your references are any missing?

Second thought, I have not seen a connection setup quite like that before (although it seems like it should work).

Try declaring it and setting it this way...

Dim objConn As New ADODB.Connection

Set objConn = CurrentProject().Connection

 
If Access2000 or above ...

Code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim intresponse As Integer
Dim objCnn As ADODB.Connection
Dim objRST As ADODB.Recordset

If Me.optCheckNew = True Then
  intresponse = MsgBox("are you sure you want to save this record?", vbOKCancel)
  If intresponse = vbOK Then
    Set objCnn = CurrentProject.Connection
    Set objRST = New ADODB.Recordset
    With objRST
       .ActiveConnection = objCnn 
       .CursorLocation = adUseServer
       .CursorType = adForwardOnly
       .LockType = adLockOptimistic
       .Source = "tblLotCreated"
       .Open
       .AddNew
       .Fields("DateCreated") = Format(Me.fakeDateCreated, "yyyy-mm-dd")
       .Fields("ProductNo") = Me.fakeProductNo
       .Fields("LotID") = Me.fakeLotID
       .Fields("QtyCreated") = Me.fakeQtyCreated
       .Fields("Shift") = Me.fakeShift
       .Update
       .Close
    End With
    Set objRST = Nothing
    Set objCnn = Nothing
    Me.frmLotCreated1_List.Requery
    Me.Requery
  End If
Else
  Me.optCheckNew = False
  MsgBox ("Please click new before insert a new record")
End If
  
Me.cmdNew.SetFocus
     
    
Exit_cmdSave_Click:
    Exit Sub

Err_cmdSave_Click:
    MsgBox Err.Description
    Resume Exit_cmdSave_Click

End Sub
 
Best not to do this in Access.
Set objConn = Application.CurrentProject.Connection
Set objRecSrc = CreateObject("ADODB.Recordset")
This will cause the connection and the recordset to be done dynamically at run time, which is not efficient in an Access Application. Dynamic is necessary in an ASP which is Browser based, but not in Access where the objects can be prebuilt at development time. Since it is dynamic ALL the correct libraries must be avialable on every PC that it is run.
Use the syntax suggested by JerryKlmns that predefines the objects.
Set objCnn = CurrentProject.Connection
Set objRST = New ADODB.Recordset

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top