Clear Access Form fields for Insert - database

I have done doing form in access for inserting records.
When open that form the field inside it appear filled with previous record l want them to be empty for allowing the user fill the filed, what should I do please!

If you just want to go to a new record just use the following in the load event
private sub yourformname_load()
docmd.gotorecord acdataform,"yourformname", acNewRec
'or
'docmd.gotorecord ,, acNewRec
To keep them from viewing previous records
me.navigationbuttons = false
To allow them to view just not edit previous records
me.allowedits = false
If you want to go to another new record when they click the ok button just put the same docmd... in the Click event of your button.

Related

Connect multiple tables in Access

I want to connect multiple tables in Access. I have a main table and then multiple smaller tables that I would like to connect. Each row in the main table belongs to one entire sub-table. I would like to have small + appear next to each row in the main table and showing the sub-tables upon clicking on the +.
I tried this via relationships but it only works for the first row (perfectly) but not for any other rows. When clicking on the other rows, they are empty and no sub-table is opening up.
Any ideas?
Per the comments if you must do this here is an example:
example main table and sub tables
example form created from the main table using the create form wizard and selecting tabular to get a better looking starting form:
note I added an unbound button to the details section and that button gets replicated for each row of data. I will show two ways of setting up the button to open the correct form.
put the form in design mode open the button's properties and open the onclick event. you can do this with the macro language but I show the code:
Private Sub openButton_Click()
'each button the detail section creates has access to the data or controls in the buttons row
DoCmd.OpenTable Me.subTableName 'if form use .OpenForm
'DoCmd.Close acForm, "mainForm" 'if want to close main form
'OpenTable (MainID)
End Sub
if the logic behind opening the form gets complicated I suggest abstracting the logic to a function. here use OpenTable instead and add the Public OpenTable function inside a code module.
Public Function OpenTable(tableID As Long) As Boolean 'function allows the option checking the return value to test if OpenTable worked
Select Case tableID
Case 1
DoCmd.OpenTable "subTable1"
Case 2
DoCmd.OpenTable "subTable2"
Case 3
DoCmd.OpenTable "subTable3"
End Select
OpenTable = True
End Function
Note: you could expand the form's header and show the mainTable as a subform in that header. Then you could add a button next to each row in that subform but outside the subform. The approach I show is easier to maintain.

fetching record id passed through url in edit view suitecrm

i have created a custom button 'create note' in list view of leads. An extra column of create note appears as shown below in link(image).
through that 'create note' button i am sending the lead id as record in url as - http://localhost/cod/suitecrm/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DNotes%26action%3DEditView%26return_module%3DNotes%26return_action%3DDetailView%26record%3Da0deb972-35e7-d909-41be-5be96467233c.
after clicking on the create note button i want to fetch that record id and want to autofill the related field lead using that record lead id in create note.
i want the same functionality that appears after opening a lead below the history tab create note with autofill related lead name on list view of lead using that button 'create note' in list view
kindly help
links for images below:
drive.google.com/file/d/1SPJlSSg1qDgtkJEw5NX_5ZaUTgW8T2m1/view
drive.google.com/file/d/1EQcg_TI7FgjXCHgHVK-nhmEqCxsce69q/view

MS Access 2013 - Populate Fields Based on Check Box

I have a form set up for data entry for new orders. When entering a new order a customer can be selected from a combo box. Shipping address, zip, state, etc. are in each customer record.
When a new order is made, the shipping destination may or may not be the the address attached to the customer.
I would like to add a check box to the form that when checked auto populates the shipping information fields to the customer's information. What would be the simplest way to achieve this?
Thanks
You should use the On click event of the checkbox.
Private Sub Checkbox_Click()
If Me.Checkbox = True Then
Me.TextboxShipDest.Value = Me.TextboxShipAdress.Value
Else
Me.TextboxShipDest.Value = Null
End If
End Sub

How do you use the SQLQuery component to run multiple queries?

I have a ListBox showing all the records for a single field (first) in a database. When users click the ListBox item I'd like the value for a different field in the db (last), same record, to be displayed. My code ListBox OnClick event code is:
SQLQuery2.SQL.Text:='SELECT * FROM Names WHERE first= :FIRST';
SQLQuery2.Params.ParamByName('FIRST').AsString := ListBox1.Items[ListBox1.ItemIndex];
SQLQuery2.Open;
ShowMessage('You selected '+SQLQuery2.FieldByName('last').AsString);
When you click an item, the expected field comes up in the MessageBox. However, if you then click a different item, nothing changes--the MessageBox shows the original field.
I don't know enough about SQLQuery components and how they interact with the underlying db to know what's happening.
[P.S. The db is sqlite3, if that matters, and I'm using Lazarus rather than Delphi, if that matters.]
You need to close your query before opening it again. If you look at the code for Open on TDataSet it sets the Active property to true. The setting code for Active first checks that the value is different before doing any work:
procedure TDataSet.SetActive(Value: Boolean);
begin
..
if Active <> Value then
begin
end;
end;
So in your case, the active property is already true and the code just exits.

MS Access keep ID field in subform filled with ID from parent form

Everytime I jump to where I can enter e new record, the ID field from the parent is empty and so the connection is lost. I am looking for a workaround.
My Setup
I have a parent form that deals with two 1:n relationships
(school-class --> pupils, school-class --> tests).
For the first relationship I used the wizard. Everything works find. For the second I show the connected tests in an unbound list. Under the list is a button opening the form for entering a new record (test) for the class I came from (parent form). So I filter the sub-form via VBA so that only the tests of the current class are shown. That works perfectly fine, too.
When moving through the tests already connected with the class the correct ID (of the class filtered) is the value of the corresponding input field. But when I come to the new new record state (all fields empty), then the connection to the parent breaks and the user has to manually enter the ID of the parent (school-class).
My Question
Is my setup correct?
Is there a better way to create a subform that offers to (only) enter a new record connected to the parent data? (Maybe without the ID input field in the subform and passing of forcing the value via VBA?)
Thank you for your time!
You can use Default Value to set the classid of Tests form but be sure the parent form is open in background or behind the pop up.
Under Property Sheet/Data tab of Tests form's classid control, enter in Default Value cell:
=Forms!parentformname!classid
Alternatively, in VBA in the Tests form's OnOpen Event:
Me.classid.DefaultValue = Forms!parentformname!classid
You can then choose to hide (Visible - No) this classid control so users do not modify it. It's always advised to never allow users control of primary and foreign keys.

Resources