473,406 Members | 2,894 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,406 software developers and data experts.

VB access incrementing a text box

I'm fairly new to access and VB. I have a form which contains several
text boxes and an insert record command button. The button is supposed
to insert a new record into the database using the text fields, and
then increment a text field by 1. The insert record part works fine,
but I cannot seem to increment a text box by one. I'm sure theres a
simple explination to this!! Here is the code behind the command
button.

Private Sub cmdInsertRecord_Click()
Dim conDatabase As ADODB.Connection
Dim strSQL As String

Set conDatabase = CurrentProject.Connection

strSQL = "INSERT INTO PHOTOSAccess (REF) VALUES (" & lblRef & ")"
conDatabase.Execute strSQL

conDatabase.Close
Set conDatabase = Nothing
[Forms]![enterRecord]![lblRef] = [Forms]![enterRecord]![lblRef] + 1

End Sub

Its the last statment i cannot get right, any ideas? The text box I
want to increment is called 'lblRef' and is on a form called
'enterRecord'.

many thanks

jon.

Nov 13 '05 #1
5 3445
Try it this way. I will assume that "enterRecord" is the name of the
form that your command button is on. If this is the case, you can
substitute

[Forms]![enterRecord]![lblRef]

with the keyword "Me"
Sub ...()
'your other code
...
Set conDatabase = Nothing

Dim i As Integer
i = Me![lblRef] + 1
Me![lblRef] = i
Me.Requery
Me.Refresh

End Sub

Note: if lblRef is a textbox you should refer to it as

txtRef

lblRef indicates a Label control. Comboboxes are referred by
cboSomething, forms use frm for a prefix, frmEnterRecord,
Queries, qryRef, Tables, tblPhotosAccess.

The goal with the prefixes is to reduce/eliminate ambiguity.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2
Hi

Thanks for the suggestion.Unfortunately Its bringing up an error:

'run time error 6 over flow'

and then debug points to the line
i = [Forms]![enterRecord]![txtRef] + 1

cheers

jon.

Nov 13 '05 #3
Hi

Thanks for the suggestion.Unfortunately Its bringing up an error:

'run time error 6 over flow'

and then debug points to the line
i = [Forms]![enterRecord]![txtRef] + 1

cheers

jon.

Nov 13 '05 #4
If you are working directly in your form you don't even need the "Me"
keyword. Use your debugger to see what is in your textbox

Sub ....
...
Debug.Print "*" & txtRef & "*"
...
End Sub

I use "*" delimiters to catch any white space. If the debugger shows
something different than a number or a number plus some invisible
character, then yes, you will get an error trying to add it to an int
var. So you may want to trap for this as follows:

If IsNumeric(txtRef) Then i = txtRef + 1
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
thanks for your help guys, much appreciated. All sorted now!

Nov 13 '05 #6

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

Similar topics

1
by: algebraist | last post by:
hi, newbie question here i play poker on partypoker and ultimate bet (both of which have clients you have to download)... i was thinking of writing a program that used the hand histories these...
2
by: Michael Thomas | last post by:
Hi everyone Do any of you know if this is possible in Access either by using the import tool or by writing a module in VB: I have a database containing information for a retail chain which,...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
1
by: jonhanks | last post by:
I'm fairly new to access and VB. I have a form which contains several text boxes and an insert record command button. The button is supposed to insert a new record into the database using the text...
3
by: nick | last post by:
Is possible for server side code to access the text of <asp:label> changed by client side javascript code?
4
by: Ken Soenen | last post by:
The code below illustrates my problem which is: I'm trying to access the TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text" produces the error--Reference to a non-shared member...
10
by: HenHouse | last post by:
Hi folks; Hey wow! First post! Hope it bears fruit... Anyway, I've been teaching myself Access since March by writing an event/contact management database for the firm I work for. It's...
1
by: Leviathan via AccessMonster.com | last post by:
I'm trying to export an Access table to a pipe-delimited text file (with no text qualifier) and it keeps wrapping the text for one of the tables. None of the fields are particularly long, so I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.