Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2007, 06:20 AM
Registered User
 
Join Date: Sep 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MRuzly
Default Multiple Field in an Event

Dear Friends

I want to creat more than one field in table on one event.
example:

staring mobile no: 7783457001
end mobile no: 7783457050

if enter starting and end mobile numbers in text box and click save button. database shuld create fields between 7783457001 and 7783457050 and save mobile numbers in table field with other two fields call <b>DeCode, DPlace</b>. pls help how can I program this in MS Access
Note: 7783457001 increment to 7783457050 (Maximum 10 Digits)

Thanks
 
Old September 4th, 2007, 10:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I don't think you mean fields, I think you mean records, is that correct? If you want to add fields, this will soon be an unworkable solution. If you want to add records, then you can create a Do Loop and write a new record with each loop. If you would like help with that, I can post ADO code, since that is all I do. If you want DAO code, someone else will have to post.

If you will use the ADO code, send me the table structure, and I can post the code.



mmcdonal
 
Old September 4th, 2007, 10:50 AM
Registered User
 
Join Date: Sep 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MRuzly
Default

Quote:
quote:Originally posted by mmcdonal
 I don't think you mean fields, I think you mean records, is that correct? If you want to add fields, this will soon be an unworkable solution. If you want to add records, then you can create a Do Loop and write a new record with each loop. If you would like help with that, I can post ADO code, since that is all I do. If you want DAO code, someone else will have to post.

If you will use the ADO code, send me the table structure, and I can post the code.



mmcdonal
Yes thats is recodes,
Table Name: DepDealer
MobileNo(10) Text
DOCode(5) Text
DSCode(5) Text


Form:
StartMN TextBox
EndMN TextBox
DOCode ComboBox
DSCode ComboBox
cmdSave command button

Example:
When enter StartMN as 7758695100, EndMN as 7758695200 and Click Save button the event should store all Mobile Numbers between 7758695100 and 7758695200 in MobileNo Field with DO Code and DS Code.

Please write ADO Code for this program.

Thanks

M. Ruzly
 
Old September 4th, 2007, 11:16 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Please tell me what these combo boxes are storing, foreign key references, or text? In other words, what is the bound column, a number or text? Then, if it is a number, do you want the number stored to maintain referntial integrity, or do you want the text stored only?

DOCode ComboBox
DSCode ComboBox


mmcdonal
 
Old September 4th, 2007, 11:28 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This is what I have so far, and if the starting number is 7758695100 and the ending number is 7758695200, then the last number in the entries will be 7758695200, not 7758695199. Is that correct?

Dim iStart As Integer
Dim iEnd As Integer
Dim sStart As String
Dim sDO As String
Dim sDS As String
Dim rs As ADODB.Recordset
Dim sSQL As String

If IsNull(Me.StartMN) or Me.StartMN = "" Then
    MsgBox "Please select the starting number", vbCritical
    Exit Sub
Else
    iStart = CInt(Right(Me.StartMN, 4))
    sStart = Left(Me.StartMN, 6)
End If
If IsNull(Me.EndMN) or Me.EndMN = "" Then
    MsgBox "Please select the ending number", vbCritical
    Exit Sub
Else
    iEnd = CInt(Right(Me.EndMN, 4))
End If

sDO = Me.DOCode
sDS = Me.DSCode

sSQL = "SELECT * FROM DepDealer"
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic

Do Until iStart = iEnd + 1
    rs.AddNew
    rs("MobileNo") = sStart & iStart
    rs("DOCode") = sDO
    rs("DSCode") = sDS
    rs.Update
    iStart = iStart + 1
Loop

rs.Close




mmcdonal
 
Old September 4th, 2007, 08:49 PM
Registered User
 
Join Date: Sep 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MRuzly
Default

Quote:
quote:Originally posted by MRuzly
 Dear Friends

I want to creat more than one field in table on one event.
example:

staring mobile no: 7783457001
end mobile no: 7783457050

if enter starting and end mobile numbers in text box and click save button. database shuld create fields between 7783457001 and 7783457050 and save mobile numbers in table field with other two fields call <b>DeCode, DPlace</b>. pls help how can I program this in MS Access
Note: 7783457001 increment to 7783457050 (Maximum 10 Digits)

Thanks
Dear mmcdonal

The program is working successfully. I kindly thank you for the help

Thanks
MRuzly

M. Ruzly
 
Old September 5th, 2007, 06:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I'm glad that worked for you. Remember you may want to force the user to enter the DO and DS codes, so be sure to use the same If Then Else statements as with the start and endMN variables. If they don't need to enter these codes, then you may want to sustitute and empty string instead, like this:

If IsNull(Me.DOCode) Or Me.DOCode = "" Then
   sDO = ""
Else
   sDO = Me.DOCode
End If

This will prevent the operation from stopping due to an improper use of Null (assigning Null to a variable.)

Hope that helps.


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Multiple Event to button in layered PopUp saqlain.abbas ASP.NET 1.0 and 1.1 Professional 1 June 28th, 2007 04:05 AM
CodeBehind: Multiple ImageButtons, One Click Event bsausser ASP.NET 1.0 and 1.1 Basics 11 October 18th, 2006 10:50 PM
Using Multiple Event Handlers in Excel chp Excel VBA 4 February 15th, 2006 06:25 PM
Multiple event handlers for a single button monuindia2002 ASP.NET 1.0 and 1.1 Professional 1 October 16th, 2005 11:22 PM
Multiple field query PLUS Durwood Edwards Access 5 July 26th, 2005 09:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.