473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

txtBeginingNumber (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 txtBeginingNumber 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
tblTicketNumbers. 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 1751
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.spam.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
>
>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
>
>txtBeginingNumber (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 txtBeginingNumber 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
>tblTicketNumbers. 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 #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 cmdCallCreateRecords_Click()

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

Me.txtStart.SetFocus
MyStart = CLng(Me.txtStart.Text)
Me.txtStop.SetFocus
MyStop = CLng(Me.txtStop.Text)
Me.cboAgentID.SetFocus
MyAgent = CLng(Me.cboAgentID.Value)

CreateRecords MyStart, MyStop, MyAgent

End Sub

Sub CreateRecords(lngStart 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.OpenRecordset("tblTicket", dbOpenTable)

For lngCounter = lngStart To lngStop
With rst
.AddNew
.Fields("TicketNo") = lngCounter
.Fields("AgentID") = 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.spam.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.spam.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
>
>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
>
>txtBeginingNumber (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 txtBeginingNumber 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
>tblTicketNumbers. 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 #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 cmdCallCreateRecords_Click()

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

Me.txtStart.SetFocus
MyStart = CLng(Me.txtStart.Text)
Me.txtStop.SetFocus
MyStop = CLng(Me.txtStop.Text)
Me.cboAgentID.SetFocus
MyAgent = CLng(Me.cboAgentID.Value)

CreateRecords MyStart, MyStop, MyAgent

End Sub

Sub CreateRecords(lngStart 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.OpenRecordset("tblTicket", dbOpenTable)

For lngCounter = lngStart To lngStop
With rst
.AddNew
.Fields("TicketNo") = lngCounter
.Fields("AgentID") = 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.spam.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.spam.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
>> >
>> >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
>> >
>> >txtBeginingNumber (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 txtBeginingNumber 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
>> >tblTicketNumbers. 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 #4

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

Similar topics

1
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...
13
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...
3
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...
3
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...
6
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: ...
20
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...
4
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...
3
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.