Allow only 8 characters in Query Search/Parameter box

Yeah but I have a macro button that corresponds with that button, so in order for me to open the report with the button, I need to have the code together
 
I put it in like this and I'm getting this message regardless of what length i search with a blank report: Object doesn't support this property or method.

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String

stDocName = "OpenReportMain"
DoCmd.RunMacro stDocName

strIdNumber = Me.Command4

If Len(strIdNumber) <> 8 Then
MsgBox "Incorrect ID, re-enter.", vbOKOnly, "Error"
Exit Sub
End If


Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
 
For starters, you didn't use the structure I recommended. You're running the macro no matter what the outcome of the test is. Second, you're setting the variable to the button rather than the textbox.
 
Ok Pbaldy,

I'm tryin my best here but coming from someone who doesn't know much, I'm kind of getting vague responses and I wasn't sure if you were combining what the previous "helper" said or if you wanted me to do something different.

If you can answer a few of my questions, maybe this will start to click because this can't be that difficult.

I have a button on my dashboard once clicked, will prompt a Access criteria search and then will display my report.

That's my set up, now in order to make this search thing, am I creating an extra form? Am i modifying the query? Am I putting this code on my dashboards button and deleting what I had before? Think of me as dumb as can be and with a little more description, I promise I won't waste your time anymore but right now I'm sooo confused.

Thanks P
 
Well, I don't know exactly what you mean by:

I have a button on my dashboard once clicked, will prompt a Access criteria search and then will display my report.

From the sound of it, depending on the look you want, I would either put the textbox on your dashboard and have the above code there, or the button on the dashboard simply opens this new form, and the above code is there. Either way, the report query uses that textbox in its criteria instead of [Enter blah]. So either

Input into textbox on dashboard/button code validates 8 characters, opens report if so, message box if not.

Or

Button on dashboard opens new form/input into textbox on this new form/button code validates 8 characters, opens report if so, message box if not.

If your dashboard is a "Switchboard" that uses the table to determine its selections, you may be stuck with the second option. I'm not sure, as I've never cared for the switchboard and don't use them.
 
Oh, that button is just a command button from the toolbox that is linked with a macro to open my report, but that report has criteria so it prompts the user for data. I will try out your solutions tomorrow though. Thanks again.
 
I actually did the combo box thing from my main screen. That works out better anyways. Thanks for everyones help tho!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom