Go to certain record in form using VBA

L

Legacy 93538

Guest
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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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 :)
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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
Back
Top