473,404 Members | 2,213 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,404 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 3444
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
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
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
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
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...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.