query question

I

iain

Hi,

Can anyone help with this one?

At the moment I have a form, where I run a query from,
based on a *Contact ID* field. At the moment I have a
prompt set up, ie [Enter Contact ID] (as the criteria in
the Contact ID field in the query) so that it runs the
query based on the contact ID entered.

Can anyone let me know if its possible to run the query
based on the Contact ID of the current record on the form,
ie cutting out the prompt stage?

Cheers,
Iain
 
I

iain

the closest I've come up with is this code :

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Glasgow Development by Contact Email"

stLinkCriteria = "[Contact ID]=" & Me![Contact ID]
DoCmd.OpenQuery stDocName, acNormal, acEdit, ,
stLinkCriteria

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click

End Sub


....but just get the error message :

Compile Error :
Wrong number of arguments or invalid property assignment.

Any ideas?

This is where I always come unstuck - I get as far as
something which should, as far as I can tell work, and
then spend ages not seeing the dumb thing thats screwing
it up.

Cheers,
Iain
 
V

Victor Delgadillo

Try the following:
Public Sub GetRecord(strKey as String)
Dim strSQL as String
strSQL = "SELECT Table1.Field1, Table1.Field2, ... " _
& "FROM Table1 " _
& "WHERE Table1.Fieldx = '" & Me.txtbox & "';"
CurrentDb().Execute strSQL
... continue with the processing...

Victor Delgadillo

-----Original Message-----
the closest I've come up with is this code :

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Glasgow Development by Contact Email"

stLinkCriteria = "[Contact ID]=" & Me![Contact ID]
DoCmd.OpenQuery stDocName, acNormal, acEdit, ,
stLinkCriteria

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click

End Sub


....but just get the error message :

Compile Error :
Wrong number of arguments or invalid property assignment.

Any ideas?

This is where I always come unstuck - I get as far as
something which should, as far as I can tell work, and
then spend ages not seeing the dumb thing thats screwing
it up.

Cheers,
Iain

-----Original Message-----
Hi,

Can anyone help with this one?

At the moment I have a form, where I run a query from,
based on a *Contact ID* field. At the moment I have a
prompt set up, ie [Enter Contact ID] (as the criteria in
the Contact ID field in the query) so that it runs the
query based on the contact ID entered.

Can anyone let me know if its possible to run the query
based on the Contact ID of the current record on the form,
ie cutting out the prompt stage?

Cheers,
Iain
.
.
 
I

iain

whoa there..too technical too fast.

whats the difference between Public and Private Sub... ?

in the select line, is that a list of the fields i want to
include in the query?

what comes after the last line / ... continue with the
processing... ?

Iain
-----Original Message-----
Try the following:
Public Sub GetRecord(strKey as String)
Dim strSQL as String
strSQL = "SELECT Table1.Field1, Table1.Field2, ... " _
& "FROM Table1 " _
& "WHERE Table1.Fieldx = '" & Me.txtbox & "';"
CurrentDb().Execute strSQL
... continue with the processing...

Victor Delgadillo

-----Original Message-----
the closest I've come up with is this code :

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Glasgow Development by Contact Email"

stLinkCriteria = "[Contact ID]=" & Me![Contact ID]
DoCmd.OpenQuery stDocName, acNormal, acEdit, ,
stLinkCriteria

Exit_Command48_Click:
Exit Sub

Err_Command48_Click:
MsgBox Err.Description
Resume Exit_Command48_Click

End Sub


....but just get the error message :

Compile Error :
Wrong number of arguments or invalid property assignment.

Any ideas?

This is where I always come unstuck - I get as far as
something which should, as far as I can tell work, and
then spend ages not seeing the dumb thing thats screwing
it up.

Cheers,
Iain

-----Original Message-----
Hi,

Can anyone help with this one?

At the moment I have a form, where I run a query from,
based on a *Contact ID* field. At the moment I have a
prompt set up, ie [Enter Contact ID] (as the criteria in
the Contact ID field in the query) so that it runs the
query based on the contact ID entered.

Can anyone let me know if its possible to run the query
based on the Contact ID of the current record on the form,
ie cutting out the prompt stage?

Cheers,
Iain
.
.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top