Is there a VB Parameter Function?

G

Guest

Hi,

Below is a short VB function that will delete the query named "TEST 1" from
my database window and pop up a message box saying "Complete!" when done.

I need a paramater VB function like this that can prompt me in a pop-up box
for the query name I wish to delete (in case I wish to delte a different
query or table without creating multiple functions like this for each
database object). Can anyone help?

Function TEST()
On Error GoTo TEST_Err

DoCmd.DeleteObject acQuery, "TEST 1"
MsgBox "Complete!", vbInformation, ""
Exit Function

TEST_Exit:
Exit Function

TEST_Err:
MsgBox Error$
Resume TEST_Exit

End Function
 
F

fredg

Hi,

Below is a short VB function that will delete the query named "TEST 1" from
my database window and pop up a message box saying "Complete!" when done.

I need a paramater VB function like this that can prompt me in a pop-up box
for the query name I wish to delete (in case I wish to delte a different
query or table without creating multiple functions like this for each
database object). Can anyone help?

Function TEST()
On Error GoTo TEST_Err

DoCmd.DeleteObject acQuery, "TEST 1"
MsgBox "Complete!", vbInformation, ""
Exit Function

TEST_Exit:
Exit Function

TEST_Err:
MsgBox Error$
Resume TEST_Exit

End Function

A Function is used when you wish to return a value, otherwise use a
Sub Procedure.

A simple, bare-boned method:

Sub TEST()
On Error GoTo TEST_Err
Dim strName as String
strName = InputBox("Delete what query?","Delete a query")
DoCmd.DeleteObject acQuery, strQuery
' Note there are no quotes around strQuery.
MsgBox "Complete!", vbInformation

TEST_Exit:
Exit Sub
TEST_Err:
MsgBox Error$
Resume TEST_Exit
End Sub

Of course you'll get an error if the query name is miss-spelled.
Trap the resulting error.
 
G

Guest

and you need to fix Fred's typo...

either use strName, or strQuery, but not a mixture of the two. ;-)

D.
 
F

fredg

and you need to fix Fred's typo...

either use strName, or strQuery, but not a mixture of the two. ;-)

D.

Good catch.
That's what happens to code when you let your fingers do the talking.
 
G

Guest

Hi Damian,

When I run this function I get an error saying "This action requires an
argument name argument". Is it ignoring the "acQuery" ?
 

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