Access Form

KAcharya

New member
Local time
Today, 17:39
Joined
Oct 7, 2011
Messages
6
Hi there,

I have created a customer database for my small business. I have a form called "customer details". This is "view only" form, can not change customer details. I have added command called "edit customer details" to this form. When command button clicked on, it opens another form called "edit customer details".

What I would like to do is when I select a customer in "customer detail" form and if I want to make any changes to this customer, I press "edit customer details" and it should open "edit customer details" form with this particular customer's details.

However it is not happening. "edit customer details" form always opens first customer's details from the "customer" table.

Can anybody help me please.
 
Where CustomerID is a Field whose Value is unique to a given Record.

In Customer Details Form
Code:
Private Sub Go2EditCustomerDetailsForm_Click()
If Not IsNull(Me.CustomerID) Then
  DoCmd.OpenForm ""Edit Customer Details ", , , , , , Me.CustomerID
 Else
  MsgBox "A Customer ID Must Be Entered First!"
 End If
End Sub
In Edit Customer Details Form
Code:
Private Sub Form_Load()

Dim rst As Recordset

If Not IsNull(Me.OpenArgs) Then
 Set rst = Me.RecordsetClone
 
 [COLOR="RoyalBlue"]rst.FindFirst "[CustomerID] = '" & Me.OpenArgs & "'"   ' Use this for a Text ID[/COLOR]
[COLOR="Red"] 'rst.FindFirst "[CustomerID] = " & Me.OpenArgs          ' Use this for a Numeric ID[/COLOR]
   End If

rst.Close
Set rst = Nothing


End Sub
In the second bit of code, notice the lines in Blue and Red.

Use the Blue line if the ID is Text, and the Red line if the ID is a Number.

Linq ;0)>
 
I am using macro. The code I am using is:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
For="CmdEditCustomerDetails" Event="OnClick"><Statements><Action Name="OpenForm"><Argument Name="FormName">Edit Customer Details</Argument><Argument Name="DataMode">Edit</Argument></Action></Statements></UserInterfaceMacro></UserInterfaceMacros>
 
I'm afraid you'll find precious little help on this, or any, Access forum with Macros. There are a limited number of tasks that can be accomplished, using them, and you are even more limited by the rigid way in which these tasks must be done.

With the possible exception of the special Autoexec Macro, very few experienced developers use them.

Any serious app is going to require code, and you'd be best served by dumping your Macro and replacing it with code, as indicated above.

Linq ;0)>
 
Hello missinglinq,
Thnk you for your help, but i dont know how to use code.
 
missinglinq is right, you are very limited with using macros

Right-Click on the button that you want to use from your customer details form to edit the record and go to properties.

On the properties pane, click 'Event' tab and first option on the list is called 'On Click'

On the drop down list, choose [Event Procedure] and click the small button to the right.

This will open up visual basic, copy and paste the code that missinglinq has provided for you above under "In Customer Details Form"
Make sure you have the name of your fields in your database where me.CustomerID has been shown.

Then save it and view your form as normal

I was in your postion once and it really does help to do some research and training first, especially in VBA coding :)
 

Users who are viewing this thread

Back
Top Bottom