Connecting Tech Pros Worldwide Forums | Help | Site Map

Access and vba in excel

Jef.Biesemans@eu.fishersci.com
Guest
 
Posts: n/a
#1: Nov 13 '05
Hello,

I have the folowing odd problem. When I execute the following code in
access I have no problem. But when I execute the same code in excel, I
get an error that I don't have read permission on the table. The table
is a linked table, but I have the permission on both databases set the
same. Could someone please help me, I can't find the answer.

Private Sub cmdGetResults_Click()
Dim qDef As QueryDef
Dim rs As Recordset
Dim db As Database
Dim J As Integer, I As Integer
Dim numberOfmeasures As Integer

Set db = CurrentDb
For J = 0 To 1
Set qDef = db.CreateQueryDef("", "SELECT Count(*) FROM tblZygo
WHERE WaferID = 26 AND kant = " & J & ";")
Set rs = qDef.OpenRecordset()
numberOfmeasures = rs.Fields(0)

If numberOfmeasures > 5 Then
numberOfmeasures = 5
End If

For I = 1 To numberOfmeasures
Set qDef = db.CreateQueryDef("", "SELECT PV, Ra, Rms FROM
tblZygo WHERE WaferID = 26 AND kant = " & J & " AND meting = " & I &
";")
Set rs = qDef.OpenRecordset()

MsgBox rs!PV & vbCrLf & rs!Ra & vbCrLf & rs!Rms
Next I
Next J
End Sub

Best regards
Jef


Larry Linson
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Access and vba in excel


I haven't done any Excel VBA in a long time, but can you use CurrentDB? I
thought that was a built-in Access object, not a general VBA object.

Larry Linson
Microsoft Access MVP

<Jef.Biesemans@eu.fishersci.com> wrote in message
news:1125990454.545895.77490@g47g2000cwa.googlegro ups.com...[color=blue]
> Hello,
>
> I have the folowing odd problem. When I execute the following code in
> access I have no problem. But when I execute the same code in excel, I
> get an error that I don't have read permission on the table. The table
> is a linked table, but I have the permission on both databases set the
> same. Could someone please help me, I can't find the answer.
>
> Private Sub cmdGetResults_Click()
> Dim qDef As QueryDef
> Dim rs As Recordset
> Dim db As Database
> Dim J As Integer, I As Integer
> Dim numberOfmeasures As Integer
>
> Set db = CurrentDb
> For J = 0 To 1
> Set qDef = db.CreateQueryDef("", "SELECT Count(*) FROM tblZygo
> WHERE WaferID = 26 AND kant = " & J & ";")
> Set rs = qDef.OpenRecordset()
> numberOfmeasures = rs.Fields(0)
>
> If numberOfmeasures > 5 Then
> numberOfmeasures = 5
> End If
>
> For I = 1 To numberOfmeasures
> Set qDef = db.CreateQueryDef("", "SELECT PV, Ra, Rms FROM
> tblZygo WHERE WaferID = 26 AND kant = " & J & " AND meting = " & I &
> ";")
> Set rs = qDef.OpenRecordset()
>
> MsgBox rs!PV & vbCrLf & rs!Ra & vbCrLf & rs!Rms
> Next I
> Next J
> End Sub
>
> Best regards
> Jef
>[/color]


Tom van Stiphout
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Access and vba in excel


On 6 Sep 2005 00:07:34 -0700, Jef.Biesemans@eu.fishersci.com wrote:

Not sure, but it's really overkill to create a querydef object for
this. Rather write:
set rs = db.OpenRecordset("<Select statement>", dbOpenSnapshot

And don't forget to clean up:
rs.Close
set rs = Nothing

-Tom.

[color=blue]
>Hello,
>
>I have the folowing odd problem. When I execute the following code in
>access I have no problem. But when I execute the same code in excel, I
>get an error that I don't have read permission on the table. The table
>is a linked table, but I have the permission on both databases set the
>same. Could someone please help me, I can't find the answer.
>
>Private Sub cmdGetResults_Click()
> Dim qDef As QueryDef
> Dim rs As Recordset
> Dim db As Database
> Dim J As Integer, I As Integer
> Dim numberOfmeasures As Integer
>
> Set db = CurrentDb
> For J = 0 To 1
> Set qDef = db.CreateQueryDef("", "SELECT Count(*) FROM tblZygo
>WHERE WaferID = 26 AND kant = " & J & ";")
> Set rs = qDef.OpenRecordset()
> numberOfmeasures = rs.Fields(0)
>
> If numberOfmeasures > 5 Then
> numberOfmeasures = 5
> End If
>
> For I = 1 To numberOfmeasures
> Set qDef = db.CreateQueryDef("", "SELECT PV, Ra, Rms FROM
>tblZygo WHERE WaferID = 26 AND kant = " & J & " AND meting = " & I &
>";")
> Set rs = qDef.OpenRecordset()
>
> MsgBox rs!PV & vbCrLf & rs!Ra & vbCrLf & rs!Rms
> Next I
> Next J
>End Sub
>
>Best regards
>Jef[/color]

Jef.Biesemans@eu.fishersci.com
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Access and vba in excel


Thanks for the respons, but I've found the problem. And Tom, thanks for
giving me the usefull information about the select statement.

Jef

Closed Thread