Topics Search

vba to write a record

vba to write a record
Views: 16
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:

More 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?

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.

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

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

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

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?

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...