Avatar billede rickie Juniormester
24. august 2006 - 08:37 Der er 10 kommentarer og
1 løsning

Connecte til ekstern database (View)

Hej,

Jeg har fölgende kode:
-----
If Not IsNull(DLookup("[No_]", "[dbo.vw_Thorn_Svenska_AB$Customer]", "[No_]=txtKundenr")) Then
sSQL = "INSERT INTO Labels ([Kundenr])" & vbCrLf & _
            "SELECT ([No_])" & vbCrLf & _
            "FROM [dbo.vw_Thorn_Svenska_AB$Customer] WHERE [No_] = " & txtKundenr.Value
          Me.Requery
DoCmd.RunSQL sSQL
    Else
        MsgBox "Kundenr. " & txtKundenr & " kendes ikke", vbExclamation

    End If
    txtKundenr = ""
    txtKundenr.SetFocus

End Sub
-----

Den henter fra en linked table (view) i Access: dbo.vw_Thorn_Svenska_AB$Customer

Den giver fölgende fejlmeddelelse:
Run time error 3078
The Microsoft Jet Database engine cannot find the input table or query 'dbo.vw_Thorn_Svenska_AB$Customer'. Make sure it exists and that its name is spelled correctly.

Er der nogen der kan gennemskue det? :-)

Mvh Rickie
Avatar billede terry Ekspert
24. august 2006 - 09:36 #1
Have you linked the view using a DSN (ODBC) connection?
If so, can you open the view directly?
Can you also make a query using the linked table? If you can then you should be able to use the view in the code above.
Avatar billede rickie Juniormester
24. august 2006 - 10:41 #2
Hey Terry,

I´ve tried to make a simple query in Access that withdraws "no_" and "name" from the view [dbo.vw_Thorn_Svenska_AB$Customer] and it works perfect, but somehow it won´t work with the code above.
It´s a ODBC connection! :-) and i can open it (doubleclick) and se all the values/customers.
Avatar billede terry Ekspert
24. august 2006 - 10:48 #3
Try setting a break point at the line with
DoCmd.RunSQL sSQL

Then run the code until you hit the break point. Then in the debug window (Ctrl+G) write

?sSQL

You will now see the contents of the variable sSQL. Copy and paste the contents into a new query to see if that works.
Avatar billede terry Ekspert
24. august 2006 - 10:49 #4
It should be easier to find the problem now.

I'm off for a while, will look again later.
Avatar billede rickie Juniormester
24. august 2006 - 11:02 #5
Now i got another message. It seems like the connection to the view works now but i get the following halt:
Data type mismatch in criteria expression.

When i do what you told me i got following:
?sSQL
INSERT INTO Labels ([Kundenr])
SELECT ([No_])
FROM [dbo_vw_Thorn_Svenska_AB$Customer] WHERE [No_] = 17116516

I´ve checked that [No_] field is the same type as in table Labels (Text) and that the value is 20. Now i´m lost :-)
Avatar billede rickie Juniormester
24. august 2006 - 11:05 #6
He he! I´ve got i working. All i needed to do was add ' & ' (where the number was, 17116516)in this line:
FROM [dbo_vw_Thorn_Svenska_AB$Customer] WHERE [No_] = 17116516
Avatar billede rickie Juniormester
24. august 2006 - 11:06 #7
Give me an answer and you´ll get your points :-)
Avatar billede terry Ekspert
24. august 2006 - 11:55 #8
Great :o)

so No_ is a text value not a number.

I'm a bit puzzled to your SQL though.

Why Select No_ with a value ('17116516') which you know is '17116516' from one table and insert it into another table?
Avatar billede terry Ekspert
24. august 2006 - 11:55 #9
Ooops
Avatar billede rickie Juniormester
24. august 2006 - 15:36 #10
It´s because the number is from one table and i need to combine it with other data that i edit, and i´m not allowed to update the original database
Avatar billede rickie Juniormester
30. august 2006 - 10:39 #11
Answer for points :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester