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

Accpac .Fetch not working

Status
Not open for further replies.

irenavassilia

Programmer
Jun 19, 2007
101
Hi Everyone,

I have a function which is suppose to get the manufacturing item number under the specified item, but my fetch is always false, this is no brainer im sure, i just have little time to figure this out and im running out of ideas, here is my code:

Sub Main(ByRef strManfItem As String)
'Declare variables here
Dim rs As AccpacCOMAPI.AccpacView
Dim DBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Dim Session As New AccpacSession
Dim strFilter As String
On Error GoTo ACCPACErrorHandler ' Set error handler

Session.Init "", "IC", "IC1140", "54A"
Session.Open "ADMIN", "ADMIN", "SAMLTD", Date, 0, 0

'Open dblink
Set DBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
'Open view
DBLinkCmpRW.OpenView "IC0305", rs

'Your code is here
With rs
.Init
strFilter = "(ITEMNO = " + strManfItem + ")"
.Browse strFilter, True
Do While .Fetch
strManfItem = .Fields("MANITEMNO")
Loop
.Close
Set rs = Nothing
End With
'Cleanup

Set DBLinkCmpRW = Nothing

Exit Sub

ACCPACErrorHandler:
Dim lCount As Long
Dim lIndex As Long
If Errors Is Nothing Then
'MsgBox Err.Description
Else
lCount = Errors.Count
If lCount = 0 Then
MsgBox Err.Description
Else
For lIndex = 0 To lCount - 1
MsgBox Errors.Item(lIndex)
Next
Errors.Clear
End If
Resume Next
End If
End Sub

ANY HELP WOULD BE GREATFUL.

THANK YOU.
 
As soon as something is resolved something else comes up lol..

Someone please help me, my fetch doesnt get anything but null value ""

In this code:

With rs
.Init
strFilter = "ITEMNO = " & strManfItem & ""
.Browse strFilter, True
.Fetch
strManfItem = .Fields("MANITEMNO")
.Close
Set rs = Nothing
End With

When debugging:

strFilter = "ITEMNO = A1-600/0"
.Browse strFilter, true (is true)

It then passes .Fetch and strManfItem is = "" when really its A1002... why is this happening?

Please help, thanks a bunch.
 
Resolved, the format of the fields were different had to trim unnecessary characters.

 
Everything is working fine but when i try to upload this on my client computer it crashes right off the bat and gives me a Run-time error 13 type mismatch, i dont get this error on my machine... so i'm really puzzled as to why its crashing...

Do you know what this might mean?

Thanks Tuba :)
 
Could be a thousand things. Edit the macro at their site, and single step run until you get to the line with the error.
 
Edit the macro on the client's computer, click Tools, References and check for anything that is MISSING. That is normal the #1 cause of macros suddenly not working.

Runtime err 13 means you are passing a string value where a numeric value is expected, or the other way around.

You also want to change the following:
Code:
 strFilter = "ITEMNO = " & strManfItem & ""
to
Code:
 strFilter = "ITEMNO = """ & strManfItem & """"

so that when debugging you will see
Code:
 strFilter = "ITEMNO = "A1-600/0""
instead of just
Code:
 strFilter = "ITEMNO = A1-600/0"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top