473,786 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding bunch of data in table usnig VBA

Hi,
Your help will be greatly appriciated.

I have a table with following fields. Table's name is tblTicketNumers

TicketNumberID (It is a key field)
TicketNumber (Text field)
AgentsName (Text field)

I have a form which is NOT BOUND to this table with following controls

txtBeginingNumb er (Type in the first number of ticket)
txtEndNumber (Type in the last number of ticket)
cboAgentsName (This is a lookup control, gets data from another table)

Typical usage:
Enter 510 in txtBeginingNumb er textbox
Enter 580 in txtEndNumber textbox
select any agent's name from cboAgentsName

Press a command button.

Behind a command button I am looking for a code to enter this data into
tblTicketNumber s. After executing this code, the table should look like
this:

TicketNumberID TicketNumber AgentsName
1 510 Skylink Travel and Tours
2 511 Skylink Travel and Tours
3 512 Skylink Travel and Tours
4 513 Skylink Travel and Tours
5 514 Skylink Travel and Tours

The table should be filled with data all the way to ticket number 580

Thanking you all in advance.
Nov 12 '05 #1
3 1774
On 22 Jan 2004 03:05:44 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

Sorry Hasanain, but the newsgroup is not a code factory. The way it
works is: you struggle, read the help files, find online code
snippets, and when you get stuck you post your efforts so far, and
hopefully others can provide help.
Good luck with working on your new skill.

-Tom.
Thanks Tom.

I agree with your design, I should be using AgentID.

I will appriciate if you could help me with VBA code since I am not
good at it.

Thanks again.

Tom van Stiphout <to*****@no.spa m.cox.net> wrote in message news:<bs******* *************** **********@4ax. com>...
On 21 Jan 2004 21:08:37 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

Bad design.
If you want a relational database, rather than AgentsName you would
use AgentID. This ID value can be looked up in the Agents table to
find the Name, Phone, etc for the agent.

Your cboAgentsName now will have (at least) 2 columns: a hidden
AgentID, and the visible AgentName.

To add the rows to the table, use a recordset.
Then in a For loop, loop from txtBeginNumber to txtEndNumber, use
AddNew to add a new row, and set the values for each field. .Update
saves the row.

-Tom.

>Hi,
>Your help will be greatly appriciated.
>
>I have a table with following fields. Table's name is tblTicketNumers
>
>TicketNumber ID (It is a key field)
>TicketNumber (Text field)
>AgentsName (Text field)
>
>I have a form which is NOT BOUND to this table with following controls
>
>txtBeginingNum ber (Type in the first number of ticket)
>txtEndNumber (Type in the last number of ticket)
>cboAgentsNam e (This is a lookup control, gets data from another table)
>
>Typical usage:
>Enter 510 in txtBeginingNumb er textbox
>Enter 580 in txtEndNumber textbox
>select any agent's name from cboAgentsName
>
>Press a command button.
>
>Behind a command button I am looking for a code to enter this data into
>tblTicketNumbe rs. After executing this code, the table should look like
>this:
>
>TicketNumber ID TicketNumber AgentsName
>1 510 Skylink Travel and Tours
>2 511 Skylink Travel and Tours
>3 512 Skylink Travel and Tours
>4 513 Skylink Travel and Tours
>5 514 Skylink Travel and Tours
>
>The table should be filled with data all the way to ticket number 580
>
>Thanking you all in advance.


Nov 12 '05 #2
Hi All,
Thanks to all who helped me.
Thanks to Tom van Stiphout, he forced me to go back to my library.

I solved the problem

My table called tblTicket has three fielsd
TicketID (Autonumber)
TicketNumber
AgentID

The other table I have is called tblAgent with two fields
AgentID (AutoNumber)
AgentName

In my form called frmTicketNumber I have two textboxes and one combobox
txtStart
txtStop
cboAgentID

I have a command button and behind this butto the code is as follows

Private Sub cmdCallCreateRe cords_Click()

Dim MyStart As Long
Dim MyStop As Long
Dim MyAgent As Long

Me.txtStart.Set Focus
MyStart = CLng(Me.txtStar t.Text)
Me.txtStop.SetF ocus
MyStop = CLng(Me.txtStop .Text)
Me.cboAgentID.S etFocus
MyAgent = CLng(Me.cboAgen tID.Value)

CreateRecords MyStart, MyStop, MyAgent

End Sub

Sub CreateRecords(l ngStart As Long, lngStop As Long, lngAgent As Long)

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim lngCounter As Long

Set dbs = CurrentDb
Set rst = dbs.OpenRecords et("tblTicket" , dbOpenTable)

For lngCounter = lngStart To lngStop
With rst
.AddNew
.Fields("Ticket No") = lngCounter
.Fields("AgentI D") = lngAgent
.Update
End With
Next lngCounter

rst.Close
Set rst = Nothing
Set dbs = Nothing

End Sub

This works fine for the intended purpose
Tom van Stiphout <to*****@no.spa m.cox.net> wrote in message news:<r7******* *************** **********@4ax. com>...
On 22 Jan 2004 03:05:44 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

Sorry Hasanain, but the newsgroup is not a code factory. The way it
works is: you struggle, read the help files, find online code
snippets, and when you get stuck you post your efforts so far, and
hopefully others can provide help.
Good luck with working on your new skill.

-Tom.
Thanks Tom.

I agree with your design, I should be using AgentID.

I will appriciate if you could help me with VBA code since I am not
good at it.

Thanks again.

Tom van Stiphout <to*****@no.spa m.cox.net> wrote in message news:<bs******* *************** **********@4ax. com>...
On 21 Jan 2004 21:08:37 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

Bad design.
If you want a relational database, rather than AgentsName you would
use AgentID. This ID value can be looked up in the Agents table to
find the Name, Phone, etc for the agent.

Your cboAgentsName now will have (at least) 2 columns: a hidden
AgentID, and the visible AgentName.

To add the rows to the table, use a recordset.
Then in a For loop, loop from txtBeginNumber to txtEndNumber, use
AddNew to add a new row, and set the values for each field. .Update
saves the row.

-Tom.
>Hi,
>Your help will be greatly appriciated.
>
>I have a table with following fields. Table's name is tblTicketNumers
>
>TicketNumber ID (It is a key field)
>TicketNumber (Text field)
>AgentsName (Text field)
>
>I have a form which is NOT BOUND to this table with following controls
>
>txtBeginingNum ber (Type in the first number of ticket)
>txtEndNumber (Type in the last number of ticket)
>cboAgentsNam e (This is a lookup control, gets data from another table)
>
>Typical usage:
>Enter 510 in txtBeginingNumb er textbox
>Enter 580 in txtEndNumber textbox
>select any agent's name from cboAgentsName
>
>Press a command button.
>
>Behind a command button I am looking for a code to enter this data into
>tblTicketNumbe rs. After executing this code, the table should look like
>this:
>
>TicketNumber ID TicketNumber AgentsName
>1 510 Skylink Travel and Tours
>2 511 Skylink Travel and Tours
>3 512 Skylink Travel and Tours
>4 513 Skylink Travel and Tours
>5 514 Skylink Travel and Tours
>
>The table should be filled with data all the way to ticket number 580
>
>Thanking you all in advance.

Nov 12 '05 #3
On 25 Jan 2004 02:11:16 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

That's the spirit ! Good for you !
-Tom.
Hi All,
Thanks to all who helped me.
Thanks to Tom van Stiphout, he forced me to go back to my library.

I solved the problem

My table called tblTicket has three fielsd
TicketID (Autonumber)
TicketNumber
AgentID

The other table I have is called tblAgent with two fields
AgentID (AutoNumber)
AgentName

In my form called frmTicketNumber I have two textboxes and one combobox
txtStart
txtStop
cboAgentID

I have a command button and behind this butto the code is as follows

Private Sub cmdCallCreateRe cords_Click()

Dim MyStart As Long
Dim MyStop As Long
Dim MyAgent As Long

Me.txtStart.Se tFocus
MyStart = CLng(Me.txtStar t.Text)
Me.txtStop.Set Focus
MyStop = CLng(Me.txtStop .Text)
Me.cboAgentID. SetFocus
MyAgent = CLng(Me.cboAgen tID.Value)

CreateRecord s MyStart, MyStop, MyAgent

End Sub

Sub CreateRecords(l ngStart As Long, lngStop As Long, lngAgent As Long)

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim lngCounter As Long

Set dbs = CurrentDb
Set rst = dbs.OpenRecords et("tblTicket" , dbOpenTable)

For lngCounter = lngStart To lngStop
With rst
.AddNew
.Fields("Ticket No") = lngCounter
.Fields("AgentI D") = lngAgent
.Update
End With
Next lngCounter

rst.Close
Set rst = Nothing
Set dbs = Nothing

End Sub

This works fine for the intended purpose
Tom van Stiphout <to*****@no.spa m.cox.net> wrote in message news:<r7******* *************** **********@4ax. com>...
On 22 Jan 2004 03:05:44 -0800, ha*******@yahoo .com (Hasanain F.
Esmail) wrote:

Sorry Hasanain, but the newsgroup is not a code factory. The way it
works is: you struggle, read the help files, find online code
snippets, and when you get stuck you post your efforts so far, and
hopefully others can provide help.
Good luck with working on your new skill.

-Tom.
>Thanks Tom.
>
>I agree with your design, I should be using AgentID.
>
>I will appriciate if you could help me with VBA code since I am not
>good at it.
>
>Thanks again.
>
>Tom van Stiphout <to*****@no.spa m.cox.net> wrote in message news:<bs******* *************** **********@4ax. com>...
>> On 21 Jan 2004 21:08:37 -0800, ha*******@yahoo .com (Hasanain F.
>> Esmail) wrote:
>>
>> Bad design.
>> If you want a relational database, rather than AgentsName you would
>> use AgentID. This ID value can be looked up in the Agents table to
>> find the Name, Phone, etc for the agent.
>>
>> Your cboAgentsName now will have (at least) 2 columns: a hidden
>> AgentID, and the visible AgentName.
>>
>> To add the rows to the table, use a recordset.
>> Then in a For loop, loop from txtBeginNumber to txtEndNumber, use
>> AddNew to add a new row, and set the values for each field. .Update
>> saves the row.
>>
>> -Tom.
>>
>>
>> >Hi,
>> >Your help will be greatly appriciated.
>> >
>> >I have a table with following fields. Table's name is tblTicketNumers
>> >
>> >TicketNumber ID (It is a key field)
>> >TicketNumber (Text field)
>> >AgentsName (Text field)
>> >
>> >I have a form which is NOT BOUND to this table with following controls
>> >
>> >txtBeginingNum ber (Type in the first number of ticket)
>> >txtEndNumber (Type in the last number of ticket)
>> >cboAgentsNam e (This is a lookup control, gets data from another table)
>> >
>> >Typical usage:
>> >Enter 510 in txtBeginingNumb er textbox
>> >Enter 580 in txtEndNumber textbox
>> >select any agent's name from cboAgentsName
>> >
>> >Press a command button.
>> >
>> >Behind a command button I am looking for a code to enter this data into
>> >tblTicketNumbe rs. After executing this code, the table should look like
>> >this:
>> >
>> >TicketNumber ID TicketNumber AgentsName
>> >1 510 Skylink Travel and Tours
>> >2 511 Skylink Travel and Tours
>> >3 512 Skylink Travel and Tours
>> >4 513 Skylink Travel and Tours
>> >5 514 Skylink Travel and Tours
>> >
>> >The table should be filled with data all the way to ticket number 580
>> >
>> >Thanking you all in advance.


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2263
by: Geoff Biggs | last post by:
Evening all, I'm trying to add a new built-in number data type to Python with its own syntax, so I'm working directly with the interpreter rather than creating my own extension module (side note: I've appended something extra to the version thing in the Makefile - I doubt this is relevant to the problem but it's probably best you have all the info). The complex data type is similar to what I'm trying to do so I've been following that as...
13
2699
by: Shannan Casteel via AccessMonster.com | last post by:
I set up two tables (one with the regular claim info and another with ClaimNumber, PartNumber, and QuantityReplaced). The ClaimNumber is an autonumber and the primary key in both tables. I made a one to one relationship between the two tables. I have a form for the parts. It includes 25 text boxes for both the part numbers and the quantities, so 50 total. I set the control sources for each of the part number text boxes to PartNumber...
3
4885
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
3
1956
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple example would be: Let's say Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and Column2, I need to do some calculations and display in as Column3. The calculations are easy and can be done in the code-behind. How to display...
6
1296
by: Dany P. Wu | last post by:
Hi everyone, I created a page which contains a two-column table. The first column has a bunch of labels, and the second a bunch of textboxes. Here's the code: ====================================================== Protected WithEvents Container As System.Web.UI.WebControls.PlaceHolder Private Sub ConstructEditTable() Container.Controls.Add(New LiteralControl("<table>" & vbNewLine))
20
2149
by: Bryan | last post by:
hello all... im trying to add a record to an sql db on ms sql server 2000, using vb.net. seems to be working.. except for one thing, one of the columns in the database is a bit datatype, and though i get no syntax errors when compiling, i get an error indicated that the data would be truncated. the field is login_status. ive tried in quotes and not, giving it an integer variable with the number 1
4
4496
by: John Siracusa | last post by:
I recently had a problem where a bunch of postgres backends were taking up huge amounts of CPU time. I found a bunch of log messages like this: NOTICE: adding missing FROM-clause entry for table "b" Which I eventually tracked to an improperly constructed query that reduced to something like this: select a1, a2 FROM a WHERE a1 = '...' AND b.b1 = '...';
3
2474
by: news | last post by:
Hi all, hope you can help me. I have recently set up a mysql database of local pubs, with a web form to add new listings (using PHP to generate an INSERT query). I've just been doing a bit of data entry, adding a bunch of new pubs, and all was going swimmingly. But suddenly it has stopped working - now when I try to add a new pub I get an error message "call to undefined function". I have not altered the script in any way since the...
4
1781
by: cacanene | last post by:
My question is what will be the fast algorithm to add records in a table based on the value of a field of other table. For example: TABLE2 contains two fields ID and DESCRIPTION TABLE1 contains three fields ID, DESCRIPTION and TOTALNUMBER Then, how to create so many rows in TABLE2 as the value of TABLE1.TOTALNUMBER If
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.