vba to write a record

I'm quite new to programming vba in access, but I have two fields (txtDateFrom and txtDateTo) on a form. If the txtDateTo is empty, I just want to save the record to the table.

If there is a value in it, I want to save it and then create extra records for each day between the two dates (inclusive).

I have got as far as the code below, but don't really know where to go form here!

Private Sub cmdAddLeave_Click() DoCmd.RunCommand acCmdSaveRecord If Not Len(Me.Me.txtDateTo & vbNullString) = 0 Then
For LeaveDate = Me.txtDateFrom.Value + 1 To Me.txtDateTo.Value
Next Else End Sub

Sponsored Links:

Related Topics

Update table via VBA code
Have a table (several hundred entries) which must be updated weekly using VBA code. I know how to write the actual VBA code (for each record) but I do not know how/where/what is necessary to open the table, read each record seq and update based on VBA code (function call return value) and to finally close table.


Write record to table
I'm working on an inventory database. I have a form based on a table (tblParts) that shows the details of a part (PartID, Description, Qty, Brand, etc.). I also have a few other unbound fields on this form to track the details on when a part is signed out (SODate, User, QtyTaken, etc.). When the "Sign Out" button is clicked, I need to write all of the information from this form as a new record in the Transactions table (tblXAct) using VBA.
I've updated records before, so I think I can figure how to change the quantity in tblParts when something is taken out or returned, but I've never had to write a record to a different table before. Can someone help me with this please?


Excel VBA filter
I've been playing around with this all day and can't seem to get it to work.

I am filtering a column of numbers for anything greater than the value of a variable. The code works when I write in the number itself, but can't write a version that uses the variable (strDate) I'm guessing the problem is the syntax but I haven't been doing VBA long enough to work out how to write it!

Selection.AutoFilter Field:=22, Criteria1:=">=20100301", Operator:=xlAnd


VBA Code on Form
I am trying to write a VBA access code that will help with displaying an error message to user trying to input new record into table, if 4 fields contain identical data. I have beenworking on this for 2 days straight now, and NOTHING seems to stop that record from inputing into the table.

Table Name: tblAwardsLog
4 fields: LastName , FirstName , Recommended , DateInitiated

All fields are TEXT fields. even DateInitiated

I have this Awards Log almost to where I want it, but just can't seem to get this one thing to work right.


Writing Access functions
I am an old FoxPro programmer (but have been out of programming for many years) and I have been through the Access basics that I have been able to find on line. So I can create tables, forms enter data the basics. I am learning VBA no problem there. Now I want to write some functions. I would like to write one function that is passed an ID and returns the last name of the person having that ID. I would like to write this function in two ways:

1. Connect to a table in my DB find the ID and return the name
2. Have the function perform a query that returns a record set from which the name is returned.

Does any one know where I can find some straight forward simple examples demonstrating this?

This is a training exercise for me to learn how to:
* Connect to tables and process data
* Create a record set and process data from the recordset
* Use debugging techniques breakpoints, run code from the immediate window etc


Write Conflict Error
here is my problem. I have a database that connects to tables through a ODBC connection (if this matters or not) and the forms are local on each persons computer. If they happen to be on the same record they get a "Write Conflict" error. Does anyone happen to know how this could be fixed? Basically if one person is in editing a record, anyone else that enters that record I would like some message to come up and tell them that this record is being edited. And then Access kicks them out. So they can't enter that record while the other person is editing it


Duplicate a record
Is there an easy way to duplicate a record in a continuous form? More yet, how would you write a query to duplicate the current record based. I would suppose some time of Append Query right? If so how would you write it?


How to move old record to another table
I am using Access to develop a database for my old aged home to store the record of the residents. When some residents move out, I do not want to delete the records forever but keep them in another table so that I can retrieve them whenever I need.

How to write VBA or marco to achieve the above purpose so that the operator can click a button to complete.


How to set values in different records?
I work with Access 2003 and I am new in VBA.
I would like some help with the following:
In a query that is sorted by field1 (this is the primary key)
I want to write this:

If field2.record(m)=field2.record (n) Then field3.record (p)="Yes" Else field3.record (p)="No"

field2 and field3 are texts
fields1 is a number
(m), (n), (p) are the numbers of records by which we must move from the first record in this query, if it sorted by field1


Access 2010: Write error on subform after upgrade to 2010 from 2007
It's complex--a main form with subforms that are writing to the same record as the main form. This week, two of us upgraded to Access 2010, while the remainder of the team stayed on Access 2007.

Suddenly, what has worked for years is producing a write error--only for the two of us on Access 2010. All others continue to work as they have been.

We are not accessing the same record at the same time. But in one of the subforms (that primarily creates records for a related table), when it attempts to write a new value into a field that is part of the main record, it gives the error: This record has been changed by another user since you started editing it, and forces you to save the record,write it to the clipboard, or drop the changes.

I have read other complaints about this and I've kept trying the things suggested--with either no success or the creation of new problems. The assertions that Access 2010 has not changed anything in this respect is very frustrating to those of us who know for certain that something has changed--even if it's just a setting...


how would you write this
how would you write so that a function will not work if the record is new or when a button with the command

DoCmd.GoToRecord , , acNewRec

meanning that if me.newrecord then don't fire up function123 but if the record is not new, fire up function


Master & Child Link without subform
1st Is possible have Master & Child Link function without adding any subform? If yes, how?

Eg: When I selected a customer "ABC Inc" from a combolist (or many more than 1 field; eg this month,sales man A and etc), all transaction record from table tbltransaction will show me all transactions in a ~*SPLITFORM*~ according what I selected, when I adding new record in the form the table tbltransaction will automatic adding new record including selection(customer ABC Inc,sales man A and etc) I make which like how parent form and subform do between master link and child link.

I did not use subform for this because I unable to add Splitform in a subform,

I try to mimic splitform in 2 subforms(1 single form and 1 datasheet), I can synchronize between single view subform and datasheet subform, but I facing problem when I adding new record and delete record and other few small problems. as my problem is very simple so I hope I can mimic subform function in Splitform, so I do not need to write many VBA code for 2 subforms(1 single form and 1 datasheet) or maybe someone can teach me how to write the VBA code which allow me mimic splitform in 2 subform.


Apply check at record level
I want to know that is it possible in VBA to apply check at record level? I explain as that I have an input form which has fields named Consumer, Rec_Date, Amount etc. For avoiding duplicate entry I apply Dlookup function on Consumer field but the requirement is that Rec_Date and amount should also be check for duplicate entry. Means The same Consumer with same Rec_Date and amount should not be entered. Have any one idea about solving the problem? If yes the please write the complete code in VBA for checking


VBA code for my unbound Search form.
I have a search form, which is now unbound from my table, and by that I mean I have gone and set the form's Record Source to remain blank. I have also gone and set the Control Source ofeach text box and combo box to also remain blank.

I did this because when I would search for a record by a particular field, by Document Number for example, the data I typed into the text box, or selected in the combo box, would then bestored as a new record in my table, which I did not want.

So, by doing this my Search button no longer works.

Now, do I need to write a VBA code consisting of information that will let me search by each field? For instance, in my code do I need to include information that will let me search by theDocument Number, and/or File Type, and/or Revision, and/or Project, and/or Manufacturer, and so forth?

I have been searching all day for example VBA codes for searching, but have not been successful.


Write Conflict
Write Conflict:

This record has been changed by another user since you started editing it. If you save record, you will overwrite the changes the other user made.

Copying the changes to the clipboard will let you look at the values the other user entered, and then paste your changes back in if you decide to make changes.

Save Record Copy to Clipboard Drop Changes


VBA Form Pulling Autonumber Field
I'm working on creating a small inventory/calibration database. Up until recently I was able to get away with using bound forms to do my data entry (perhaps much to the chagrin of the pros here). Now I've run into a situation where I want to enter in calibration information and it requires me to write to two tables so I can produce the query/report I want.

The reason I'm doing this is tblCalLog has general calibration information, just the equipment and date/time it was checked, this is so i can run a report/query to show what instruments will be needing calibration after X months. tblCalWL is the specific table with the calibration information for the well or the instrument, i.e. the actual measurements taken and any associated notes. tblCalLog will hold ALL calibrations and then tables such as tblCalWL will be underneath that holding specific information for each tblCalLog record.

One more question. When I write to tblCalLog, it creates a new record, how do I pull the ID (autonumber field) that was just created in tblCalLog and write it to tblCalWL so they're related?


button to move from record to record?
How can I write the code behind the button to move from record to record. I already write the following code behind the button but it is not working.

BindingContext(StudentDataSet, "mytable").Position = 1


Write data to second table
My form use tblData as its Record Source but I have 1 unbound textbox txtOutput who's value I want to write to field OutPut on tblOutPut.


Form to write record to specific table based upon a value?
Is there a way to get a form to write a record to a specific table based upon a value?

Ideally this value would be True/False ie a check box or via a selection.

I have one form to input data but I want the record to be written to one of 5 fields based upon a value


How to Read Record ID from New Record
Access 2010. I am writing a VBA routine to load some permanent tables with data from a temporary table that contains data from a spreadsheet. As my routine steps through the records in the input recordset, after it creates one record in one table it needs to retrieve that record's ID so it can write it into the new records in a table that will be linked to it. The code Itried to use looks like this:

If NewSub Then
rstO1!SubElementName = SubName
NewSub = False
End If
rstO1.Update
ParentID = rstO1!ComElemID

I thought that I would be able to retrieve the new output ID after doing the .Update but it fails on the next statement. How am I supposed to do this?