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:

Similar posts...

 

Update table via VBA code

Update table via VBA code Icon
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

Write record to table Icon
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

VBA Code on Form Icon
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

Excel VBA filter Icon
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
 

How to set values in different records?

How to set values in different records? Icon
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
 

Writing Access functions

Writing Access functions Icon
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
 

How to move old record to another table

How to move old record to another table Icon
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 prevent Write Conflict Error

How to prevent Write Conflict Error Icon
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

Duplicate a record Icon
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?
 

VBA code for my unbound Search form.

VBA code for my unbound Search form. Icon
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.