Procedure for a form

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hello All,

I am a beginner when it comes to Access and wanted to know how to write
a code for my database. Arvin suggested a code like this


Sub cmdMyButton_Click (Cancel As Integer)
On Error GoTo Error_Handler

If Me.txtSKU < Val("66666 66666") Then
DoCmd.OpenReport "rptReport 1", , "SKU = '" & Me.txtSKU & "'
Else
DoCmd.OpenReport "rptReport 2", , "SKU = '" & Me.txtSKU & "'
End If

Exit_Here:
Exit Sub
Error_Handler:
MsgBox "You really screwed up this time", vbOKOnly, "Say FOOL!"
Resume Exit_Here
End Sub


I want a form so that the user can type in the product sku and if it is
within a certain range then a certain report will open. i.e. product
skus between 75000 00000 through 75000 00800 then report 1 will open
product skus 68000 00000 through 68000 00400 then report 2 will open and
everything outside these ranges report 3 will open.

And the second part of my question is to set this up I made a form with
a text box so the user could type in the sku along with a button. Is
this code supposed to be a procedure for the button. If so what in this
code looks at what has been typed in the text box. I am sorry if these
are stupid questions I really am not familiar with Access or VBA for
that matter.

All help is very much appreciated
Thank you,
David
 
Better yet I have a combo box that list all the product skus in one of
my tables is it possible to write a code for the combo box instead of
the text box.
 
The first line ...

Sub cmdMyButton_Click (Cancel As Integer)

.... indicates that the code was intended to be used as the Click event
procedure of a command button named "cmdMyButton".

The third line ...

If Me.txtSKU < Val("66666 66666") Then

.... will compare the numeric value of the string "66666 66666" to the
contents of a text box named "txtSKU". 'Me' in VBA code refers to the class
module in which the code is running. For our current purposes, you can think
of it as referring to the form. So think of Me.txtSKU as meaning "the
control named txtSKU that is on the form behind which this code is running".
 
Back
Top