OnClick Event Procedure

S

Sondra

I have an edit form that I want to create a command button
on that will close the form and reopen it. The reason
being that the form is run on a criteria query that asks
the user to enter the document number they want to
update. I wrote a macro that closes the form and reopens
it, and that seems to work, but I would prefer to have an
onclick function.

Any help would be appreciated.

Thanks.

Sondra
American Red Cross
Give the Gift of Life Donate Blood
 
S

SusanV

I have a similar form (for searching) and I added a new button (Search
again) and simply used the wizard to have it open the same form. Seems to
work well - the original instance closes and the user is presented with the
criteria box.
 
M

Mark

Instead of closing the form and reopeing it, why not just change the record
source and then requery the form?
Off the top of my head, something like:

intDocNum=Inputbox("Enter a document number")
strSQL="Select * From MyDocumentsTable Where DocumentNumber = " & intDocNum
Me.RecordSource=strSQL
Me.Requery
 
G

Guest

I attempted this, but it doesn't run my criteria from my
query. What might I be doing wrong?

I put a new command button on
The wizard asked for my information
I chose open new form
Chose the name of my form
Asked if I wanted to open all records or specific record.

I entered all records with the hopes it would run the
query and ask my criteria.

No luck.

any advise??
 
S

Sondra

Help:

I tried this and it seemed to be okay until I got to this
line:

Me.RecordSource=strSQL

What is this??

Thanks.
 
M

Mark

Me.RecordSource=strSQL should set the form's record source to the new query
definition made in the line that starts out with strSQL="Select..." Since I
made up this code in my head and didn't test it, the syntax most likely
needs a little tweaking. Try building the query with the query builder, and
put a value in the criteria row for the document number field. View the
query as SQL and note how it's put together. You can copy it and paste it
into the VBA code and fine tune it to work. It probably needs some
parentheses or other punctuation.
 
S

SusanV

I have the form based on a query, and the MCode field (number) is what they
are searching for in the query:

Like '*' & [Enter the MCode you would like to view please] & '*'

All other fields are simply viewable, with no further definition. They can
also search the MCode Title by keyword using the same query layout, but the
field Title is set to this criteria:

Like '*' & [Enter a keyword to search by please] & '*'

I hope that helps, I'm not sure if I've been clear...

Susan
 
S

SusanV

I meant a different query using the same layout, sorry

SusanV said:
I have the form based on a query, and the MCode field (number) is what they
are searching for in the query:

Like '*' & [Enter the MCode you would like to view please] & '*'

All other fields are simply viewable, with no further definition. They can
also search the MCode Title by keyword using the same query layout, but
the field Title is set to this criteria:

Like '*' & [Enter a keyword to search by please] & '*'

I hope that helps, I'm not sure if I've been clear...

Susan


I attempted this, but it doesn't run my criteria from my
query. What might I be doing wrong?

I put a new command button on
The wizard asked for my information
I chose open new form
Chose the name of my form
Asked if I wanted to open all records or specific record.

I entered all records with the hopes it would run the
query and ask my criteria.

No luck.

any advise??
 

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