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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Novice needs assistance with VBA on form

Status
Not open for further replies.

jwrdanka

Technical User
Aug 15, 2008
9
US
I have a form that was working as required until management decided to through a wrench into it by taxing my mind.........This form is used for a simple database to put stock away in a warehouse, assigning it to a location and updating a transaction table when completed.
Here is the wrench.......If the item being received is not on a list management wants it to look at the historical usage and decide if it should be stocked or not.
The not on list wasn't a problem until they put the lookup for usage.
I created the following code but it goes directtly to the second scenerieo and skips the first one, where the item is not on the list but has history of usage.
At first I used the isnull statement but I kept getting an error of "Invalid use of Null" so I scanned the internet for advice and assigned values first........I know that this is NOT CORRECT but it seems to be WAY over my head. Any help???



Private Sub cmdLookup_Click()
On Error GoTo Err_cmdLookup_Click
DoCmd.Echo fals
DoCmd.SetWarnings False


Dim SQLINS As String
SQLINS = "INSERT INTO Data([Branch],[STO],[Material]) VALUES ('" & Me.LookupBranch & "','NOT ON STO ','" & Me.ItemNo & "')"
Dim DValue As Double
Dim txtSTO As String

txtSTO = IIf(IsNull(Me.txtSTO), "N/A", Me.txtSTO)
DValue = IIf(IsNull(DLookup("[AvgDmd]", "qry_AvgUsage", "[Item Number]='Me.ItemNo'")), 0, DLookup("[AvgDmd]", "qry_AvgUsage", "[Item Number]='Me.ItemNo'"))

DoCmd.RunMacro "Filter"

If txtSTO = "N/A" And DValue <> "0" Then


DoCmd.RunSQL SQLINS
DoCmd.OpenQuery "0004_qryMorningRefresh4-CurrentBin"
DoCmd.OpenQuery "0005_qryMorningRefresh5-DefaultBin"
DoCmd.RunMacro "Filter"

Else


If txtSTO = "N/A" And DValue = "0" Then

DoCmd.Echo True
DoCmd.SetWarnings True
MsgBox "B30 Item", vbExclamation

Else


If txtSTO <> "N/A" Then
DoCmd.RunMacro "Filter"

DoCmd.Echo True
DoCmd.SetWarnings True
End If
End If
End If

DoCmd.Echo True
DoCmd.SetWarnings True
Exit_cmdlookup_Click:
Exit Sub


Err_cmdLookup_Click:
DoCmd.Echo True
DoCmd.SetWarnings True
MsgBox Err.Description
Resume Exit_cmdlookup_Click:


End Sub
 
Never mind, I figured it out and got it working (sorry for the bad spelling, it never was one of my strong points!).
The issues was with the Dlookup and the number of quotation marks, didn't know I needed so many!.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top