Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

go to the new record... 2

Status
Not open for further replies.

daniels012

Technical User
Jan 19, 2005
55
US
In this code It's not taking me to the new record. I see it add the data with the new number WIL-216. Then I start to edit the sheet and I find I am in record WIL-215. I can scroll and get to WIL-216, but sheet doesn't automatically go there? Any help would be great.

Code:
Private Sub CopySample_Click()
   Me!SampleNumber.SetFocus
   DoCmd.RunCommand acCmdSelectRecord
   DoCmd.RunCommand acCmdCopy
   DoCmd.RunCommand acCmdPasteAppend
   DoCmd.GoToControl "SampleNumber"
   a = Split([SampleNumber], "-")
   a(1) = a(1) + 1
   [SampleNumber] = Join(a, "-")
End Sub

I guess I need something to take me to the new record??

Thank You,
Michael
 
Somewhere in there (before the append?), try:

[tt]docmd.gotorecord,,acnewrec[/tt]

Roy-Vidar
 
Got a runtime error (5)
at this line
Code:
a = Split([SampleNumber], "-")

Michael
 
Just tested those copy/append thingies for the first time. On my setup, after the pasteappend, I'm located on the new (newly appended) record. There shouldn't be any need to move...

In the initial code, you're using three ways of addressing one control, try just the following (just a rewrite, but with declaration of the array):

[tt] dim strNo() as string
strNo = split(Me!SampleNumber.value, "-")
strNo(1) = val(strNo(1))+1
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
Me!SampleNumber.value = Join(strNo, "-")[/tt]

If you mean you don't visually see the correct record, you could try moving to the last record

[tt]docmd.gotorecord,,aclast[/tt]

Roy-Vidar
 
Again,
I am getting runtime error "5"
Code:
strNo = Split(Me!SampleNumber.Value, "-")

The code used to work just fine???
Now all the sudden I'm getting this runtime error??
 
If you have code that worked fine, then use it.

What is the value of Me!SampleNumber when it's run (use msgbox me!samplenumber or debug.print me!samplenumber)

Could perhaps use split(cstr(me!samplenumber.value),"-")?

Is something different now from when it was working? Different machine, version, os...? Is there a problem with missing references? (in VBE - Tools | References - check for any marked as missing)

Roy-Vidar
 
The only difference is when I tried to add the code you suggested. Then I removed it and... no luck?

I'm not sure what is up?
 
This is the input mask for Sample Number if that helps?

>LLL\-000;0;_

 
If you display a unique record key on the form and then set the focus on it you can then use the findrecord command to go to that record. Your example has you going to a control not a record.

Hope this helps !
 
OK
since the a= split does not work!
Is there another way to add the next number to the sample number? Sample Numbers are like: WIL-215 or STU-201 etc.
I need it to put the next number in if possible, ie:
WIL-216 or STU-202

Thank You,
Michael
 
Have you tried to replace this:
dim strNo() as string
By this:
Dim strNo As Variant

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another way:
[SampleNumber]=Left([SampleNumber],InStr([SampleNumber],"-")) & (1+Val(Mid([SampleNumber],InStr([SampleNumber],"-")+1)))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Would I add this as a function in the code? And Where?

Michael
 
Can you please post your actual code for the Click event procedure ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Here it is :
Code:
Private Sub CopySample_Click()
   Me!SampleNumber.SetFocus
   DoCmd.RunCommand acCmdSelectRecord
   DoCmd.RunCommand acCmdCopy
   DoCmd.RunCommand acCmdPasteAppend
   DoCmd.GoToControl "SampleNumber"
   a = Split([SampleNumber], "-")
   a(1) = a(1) + 1
   [SampleNumber] = Join(a, "-")
End Sub
 
And which line is highlighted when you get the error "5" ?
If the Split line, what is displayed when you let the mouse pointer on [SampleNumber] ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is the area that is highlighted:
a = Split([SampleNumber], "-")
When I have the mouse over "a" it says empty
When I have the mouse over "SampleNumber" is says WIL-215

WIL-215 is the previous Sample number
 
Quite strange ... (all seems normal)
You may try to replace this:
DoCmd.GoToControl "SampleNumber"
a = Split([SampleNumber], "-")
a(1) = a(1) + 1
[SampleNumber] = Join(a, "-")
By this:
Me!SampleNumber.SetFocus
Me!SampleNumber=Left(Me!SampleNumber,InStr(Me!SampleNumber,"-")) & (1+Val(Mid(Me!SampleNumber,InStr(Me!SampleNumber,"-")+1)))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes!
Thank You so much. This seems to be working very well. I even added another line at the end
Code:
DoCmd.GotoControl "SpecialInstructions"

It seems to be doing fine!!

Thank You for your patience... I am very new when it comes to coding. And you are very kind

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top