From help

  • Thread starter Thread starter Rodney James
  • Start date Start date
R

Rodney James

Can some advice me on how to create in a form

a button that saves/updates the current record that a user is working on
with out having to go form one record to another
A button that will create a duplicate record by clicking it.
 
It is not necessary to move to a different record for it to update. If you
close the form, it will update; however, if you want a button on the form to
update it manually, all you need in the button's click event is:
If Me.Dirty Then
Me.Dirty = False
End If

Are you saying you want to create an identical record in the same table?
Why would you do that? If you have a primary key, you can't do that. If you
don't have a primary key, your database design is lacking. If you want to
duplicate a record in another table, say for history purposes, etc., then
write the SQL to append the data in the form to the other table.
 
In design view of the form, put a command whereever you want it to be.
Open the Properties dialog for the button.
Select the Events tab.
Click the command button with the 3 dots to the right of the On Click event.
Select Code Builder.
Enter the code in the VBA editor when it opens.

If Me.Dirty Then
Me.Dirty = False
End If
 
I got the update button thanks

Now The Copy button

I have an autonumber as my primary key so If it makes a copy wouldnt the
autonumber give it a new number?
 
Create an append query that adds a record to the table using the values of
your controls. For example, lets say you have a field in the table named
[Company_Name] and the control on the form is txt.CompName.
Create a new query in design view.
Select your table as the Append To.
In the Field row, enter the name of the control
Forms!MyFormName!txtCompName
In the Append To row enter the name of the field
[Company_Name]

Do this for all the fields Except the autonumber field (it will take care of
itself)

Then the code behind the button is simple:
CurrentDb.Execute("QueryNameHere"), dbFailOnError
 
Ok I got that thanks I have another how to questions if you are up for it I
really appreciate all your help

In my form I want to be able to filter down what records users are working
with in the list.



I have a few drop down tables that the filter would be applied from: Project
Status, Project Type, Product Type



So for instance. I have 100 Records



I choose a field in Project status to a particular status "Project in
Progress" now I have 50 records in the form that match that criteria



I then choose a field in Project Type to a particular type "Lighting" now I
have 25 records in the form that match this and the preceding criteria.



I lastly choose a field Product Type and pear down the list to 5 records
based on the three fields



I want the filter to work based on any combination of the three fields
 
I would suggest a command button that would apply the filter. It would be
something like this in the Click event:

Dim strFilter As String

If Not IsNull(Me.ProjectStatus) Then
strFilter = "[ProjectStatus] = '" & Me.ProjectStatus & "'"
End If

If Not IsNull(Me.ProjectType) Then
If Len strFilter > 0 Then
strFilter = strFilter & " AND "
End If
strFilter = strFilter & "[ProjectType] = '" & Me.ProjectType & "'"
End If

If Not IsNull(Me.ProductType) Then
If Len strFilter > 0 Then
strFilter = strFilter & " AND "
End If
strFilter = strFilter & "[ProductType] = '" & Me.ProductType & "'"
End If

Me.Filter = strFilter
Me.FilterOn = True
 
Back
Top