Syntax adding + 1

BBryan

Registered User.
Local time
Today, 12:43
Joined
May 28, 2010
Messages
23
Hi,
Can some help me. I'm not sure of the syntax
I wanted to double click in text box and Add the LastRtgNo + 1
I have this. The way I wrote the [LastRtgNo] + 1 is not right.
I tried with a ([LastRtgNo]) + 1 and a few other ways Can't figuire it out



Private Sub RtgNo_DblClick(Cancel As Integer)
If IsNull(RtgNo) Then
RtgNo = [LastRtgNo] + 1
Else
RtgNo = Null
End If
End Sub

Thanks.
 
Perhaps like this:
Code:
If IsNull(RtgNo) Then
   if isnumeric([LastRtgno]) then
      RtgNo = Val([LastRtgNo]) + 1
   end if
Else
   [COLOR=Red][B]RtgNo = Null[/B][/COLOR]
End If
Is RtgNo the name of a textbox? Setting Null to it will cause an error.
 
BBryan,

Are RtgNo and LastRtgNo the names of controls on your form? Bound controls? If so, I see nothing wrong with your code (although I would normally always follow the convention of qualifying controls with Me. as in:
Me.RtgNo = Me.LastRtgNo + 1

So, what does "is not right" mean, in practice? What is actually happening? Error message? Incorrect value allocated? Nothing at all? Can you give a specific example?
 
No idea Steve. My brain is wrapped up in a bubble at the moment. That doesn't hold :)
 
Hi
Sorry I had to do something But the RtgNo is the text box I want to add the last RtgNo +1 and the Last RtgNo is a unbound textbox from a Query in my Form

I tried both ways and It still doesn't work
It Shows an error in
Me.RtgNo = Me.LastRtgNo + 1

and the other way
If IsNull(RtgNo) Then
if isnumeric([LastRtgno]) then
RtgNo = Val([LastRtgNo]) + 1
end if
Else
RtgNo = Null
End If

Stops at End if. I tried putting End sub but doesn't reconize it
 
Hi,
I think the syntax is not right because if I use this
Private Sub Rt_UtNo_DblClick(Cancel As Integer)
If IsNull(RtgNo) Then
RtgNo = LastRtNo
Else
RtgNo = Null
End If
End Sub

It enters the LastRtgNo But I want the next number
The Textbox itself is text and not a number as sometimes I have to a alpha text to this number
 
I still don't follow. What do you mean by the next number? Give specific examples.
 
Hi,
I have a DlookUp from the LastRtgNo textbox that is from a query
when I put
Me.RtgNo = Me.[LastRtgNo] + 1
popup says Type mismatch

I think by putting the +1 is looking for a number where I have text using a number
(field is a Text type)

In the RtgNo feild I may have this Rtg01,Rtg-02,Rtg-03R1,Rtg-04T1 etc...
the DLookUp goes to the Last number I used. I would like to just add the next text Number and double click it into the text box

thanks
 
BBryan,

What does "next text number" mean? You really need to give us some more to go on here - my clairvoyant assistant has the day off so I'm having to rely on normal logic.

So if RtgNo is "Rtg-04T1" then next is "Rtg-04T2"??
 
Hi Steve

Thanks for help
I will try to word this better
I see that +1 is to add 1 to a number. I want to add the next seqence number in the text data feild and that is where i think I have the wrong syntax.

No the next number would start as Rtg-05, the Next Rtg-06 and depending on the situation there are only a few cases where it would have to add manuallyR1 to get Rtg-06R1
I want to get the next seqence number without the R! etc..in the RtgNo text data feild meaning the next number would be Rtg-05, Rtg-06, Rtg-07 etc..
I would manually put in the xxR1,xxT1 after the number when needed.

This is where i think I have the wrong syntax.
Like if I want to get AA, next Number would be AB, then AC, AD etc... then BA, BB, BCetc..

I hope I explained it good enough
Thanks
 
BBryan,

I am still not sure I understand what you mean with the AA and AB. But for your specific example of the Rtg-05, then I think you could do like this:

Me.RtgNo = "Rtg-" & Format(Val(Right(Me.LastRtgNo))+1,"00")

See if that helps point you in the right direction.
 
Hi Steve
I just tried that and An error says
Complile error
Augment not optional
comes up yellow on the Right
Me.RtgNo = "Rtg-" & Format(Val(Right(Me.LastRtgNo)) + 1, "00")
 
Hi Steve,
Thanks for your help
I put this in a query
NextRtgNo: "Rtg-" & Format(Right([RtgNo],2)+1,"00")
Which now gives me the next number I need
and I am using this for my DlookUp

THanks for your help
BBryan
 
BBryan,

My apologies for the error in my earlier expression.

It looks like it will work without the Val function, but I still recommend using it. Thus it should be:

NextRtgNo: "Rtg-" & Format(Val(Right([RtgNo],2))+1,"00")
 
Hi Steve,
Sorry I didn't get back to you yesterday I had to do something and then it was home time
I changed my Qy a bit to NextRtgNo: "Rtg-" & Max(Format(Mid([RtgNo],5),"000"))+1 which works fine But if i put the Val into this NextRtgNo: "Rtg-" & Max(Format(Val(Mid([RtgNo],5),"000"))+1
An error says Data MisMatch

Thanks
 
BBryan,

No, the parentheses are in the wrong place. And you should get the Max before applying the Format. I think (without testing!) that this would be better:
NextRtgNo: "Rtg-" & Format(Max(Val(Mid([RtgNo],5)))+1,"000")
 
Hi Steve,
I tried this and I still get the error
Data Mismatch - NextRtgNo: "Rtg-" & Format(Max(Val(Mid([RtgNo],5)))+1,"000")

I tried this way with out the Val and it said Invalid Syntax or inclose your text data in quotes - NextRtgNo: "Rtg-" & Format(Max(Mid([RtgNo],5)))+1,"000")

Thanks BBryan
 
I think you're trying to save a string into a number field.

NextRtgNo indicates this could be a number field.
 
Hi Steve,
In my Table I have the RtgNo as a Text Data Type.
 

Users who are viewing this thread

Back
Top Bottom