Go to certain record in form using VBA

Jessicaseymour

Active Member
Joined
Apr 8, 2008
Messages
268
Hi

I am trying to build a bit of code which will search and go to a record in the form Boxes. It shoudl first check to see if the number is valid in the table and then go to that record in the form.

However I can not seem to figure how to get it to go to the correct record number. So far I have the following code:

Code:
<code>Dim Ref As Integer Dim strSQL As Integer Dim stWhereStr As String Set db = CurrentDb() Ref = Me.Text4.Value stWhereStr = "[Box Number] = " & Ref strSQL = DCount("Box Number", "Boxes", "Box Number = " & ) If strSQL = 0 Then     MsgBox "This is box number does not exist. Please try again." Else     DoCmd.OpenForm "Boxes", acViewNormal     [COLOR=#ff0000]DoCmd.GoToRecord acDataForm, "Boxes", acGoTo, [/COLOR]</code>[COLOR=#ff0000]<code>stWhereStr</code>[/COLOR]<code>     DoCmd.Close acForm, "Box Search", acSavePrompt End If</code></pre>

However When I run this code it produces an error when it gets to the line highlighted. it produces the error "Run-time error '2498': An expression you entered is the wrong data type for one of the arguments"

Does anyone know how to make it so the code goes to correct record in the form?

Thanks

Jessicaseymour
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Kyle123

Well-known Member
Joined
Jan 24, 2012
Messages
2,708
They are ;) that's the point.

If you cross post it's good practice to include the link to the other site, that way people won't spend time working on a solution if you already have one elsewhere :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,838
Messages
5,598,383
Members
414,234
Latest member
grlevesq

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top