macro help

h46

New Member
Joined
Dec 27, 2004
Messages
2
i am trying to create a button in my database that opens a form and also opens find and replace so the user can then search for records.

i already have a button that opens the form, but i do not know how to make it automatically open find and replace, maybe i need to add some code at the end of what i already have (code that opens the form when the button is clicked).

if this is not possible i have also created a macro that opens find and replace, so could i somehow add some code to run this macro?

thanks, any help will be appreciated :rolleyes:
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello,

what are you trying to find and replace?
Do you actually want to just Find the record and let the user Edit it?
or do you want a find/replace to happen automatically.

You could run an update query to achieve the second one, or just a select to run the first.

Can you expand on your requirements and where the Replace comes into it?

Cheers,
 
Upvote 0
i just need to find a record i am only trying to use find and replace because it is the only way i know in which to find a record by inputting search criteria.
 
Upvote 0
What you need to do is design a Query, in the Criteria part
Right Click and select build.
You can then locate a control on the main form, say a textbox, which will house your value/criteria.

Then you can build a form based on the query,
when you hit the button on your main form the value in the textbox becomes your Query Criteria when the form open

Hope that makes sense, give it go and ask some more question if you need to,

cheers,
 
Upvote 0
When you add a command button on a form make sure the Toolbox Wizard is on.

Access should then guide you through the process of creating a button to open a specific form.

The code generated by this process would look something like this:

Code:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "MyForm" ' set name of form to open

    DoCmd.OpenForm stDocName, , , stLinkCriteria ' open the form

Exit_Command0_Click:
    Exit Sub

Err_Command0_Click:
    MsgBox Err.Description
    Resume Exit_Command0_Click
    
End Sub

Notice the stLinkCriteria variable. You can use this to open a the form at a specific record.

The general syntax for the variable is something like this:

stLinkCriteria = "[MyField]=" & MyRecord

MyRecord needs to be set to return the record you require.

You could do this various ways eg

1. User input via an InputBox

2. Base it on a control on the current form.

BTW you could add code to close the first form if required.
 
Upvote 0

Forum statistics

Threads
1,221,838
Messages
6,162,286
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top