VBA rs.EOF

0

Witam,

Mam makro z kodem:

40f3997ef6.png

Na czerwono podkreśliłem miejsce, w którym się wykrzacza z błędem 3704 - 'Operacja nie jest dopuszczalna,gdy obiekt jest zamknięty'.
Nie bardzo wiem o co mu chodzi.

Kod procedury, do której się odnosi makro to:

 BEGIN

 delete from faktoring1
 delete from faktoring2


insert into faktoring1
 
   select 
		rtrim(o.odbiorca_idn) as Odbiorca,
		rtrim(replace(n1.dok_idm,' ','')) as [Numer faktury],
		convert(date,n1.datoper,120)as [Data wystawienia],
		convert(date,n1.datzap,120) as [Termin płatności],
		n1.kwota as [Wartość faktury],
		replace(k.nip,'-','') as [Identyfikator podatnika]
		--n2.dok_idm
		--SUM(n.kwota) as [Suma należności]	
		
						
	from fk_naleznosc n1
	--join fk_naleznosc n2 on n2.dok_idm = replace(n1.dok_idm,' ','')
	join fk_stronarozrach s on s.stronarozrach_id = n1.stronarozrach_id
	join kontrahent k on k.identyfikator_num = s.identyfikator_num
	join fk_konto ko on ko.konto_id = n1.konto_id
	join odbiorca o on o.kontrahent_id = k.kontrahent_id
	join cechodb co on co.odbiorca_id = o.odbiorca_id
	
	where	co.wartoscparametru = 'MILLENNIUM FAKTORING' 
			and n1.waluta_id = 1  
			and (LEFT(ko.konto_idm, 6) IN ('200-01')) 
			--and (LEFT(ko.konto_idm, 6) <> ('200-0A'))
			and k.nip is not null 
			and n1.datzap between @dataod and @datado
			 
	group by o.odbiorca_idn, n1.dok_idm,n1.kwota,n1.datoper,n1.datzap,k.nip--,n2.dok_idm
	
	order by Odbiorca


	
insert into faktoring2

  select 
		rtrim(o.odbiorca_idn) as Odbiorca,
		rtrim(replace(n1.dok_idm,' ','')) as [Numer faktury],
		convert(date,n1.datoper,120)as [Data wystawienia],
		convert(date,n1.datzap,120) as [Termin płatności],
		n1.kwota as [Wartość faktury],
		replace(k.nip,'-','') as [Identyfikator podatnika]
		--n2.dok_idm
		--SUM(n.kwota) as [Suma należności]	
		
			
				
	from fk_naleznosc n1
	join fk_naleznosc n2 on n2.dok_idm = replace(n1.dok_idm,' ','')
	join fk_stronarozrach s on s.stronarozrach_id = n1.stronarozrach_id
	join kontrahent k on k.identyfikator_num = s.identyfikator_num
	join fk_konto ko on ko.konto_id = n1.konto_id
	join odbiorca o on o.kontrahent_id = k.kontrahent_id
	join cechodb co on co.odbiorca_id = o.odbiorca_id
	
		
	where	co.wartoscparametru = 'MILLENNIUM FAKTORING' 
			and n1.waluta_id = 1  
			--and (LEFT(ko.konto_idm, 6) IN ('200-0A')) 
			and (LEFT(ko.konto_idm, 6) <> ('200-0A'))
			and k.nip is not null 
			and n1.datzap between @dataod and @datado
			 
	group by o.odbiorca_idn, n1.dok_idm,n1.kwota,n1.datoper,n1.datzap,k.nip--,n2.dok_idm
	
	order by Odbiorca
	
	select 	
		f1.Odbiorca,
		f1.[Numer faktury],
		f1.[Data wystawienia],
		f1.[Termin płatności],
		f1.[Wartość faktury],
		f1.[Identyfikator podatnika] 
	from faktoring1 f1 
	
	where replace(f1.[Numer faktury],' ','')  not in (select f2.[Numer faktury] from faktoring2 f2)
	
	order by f1.Odbiorca

		
END

Procedura pod bazą wykonuje się prawidłowo.

0

Próbowałeś już z "SET NOCOUNT ON;" na początku procedury składowanej?

0

Tak. Dalej to samo.

1 użytkowników online, w tym zalogowanych: 0, gości: 1