|
|
Hi Groupies
I am trying to use Open Arguments to open a form and find a matching inventory item. If the item does not exist I want to go to a new record. I borrowed the code from an old thread but I can not quite get it to work for me.
I keep getting "Else without If" when I compile the code.
Private Sub Form_Load()
If Len(Me.OpenArgs) > 0 Then With Me.RecordsetClone .FindFirst "[Sku Number]=" & Me.OpenArgs Else <BREAK POINT> If .NoMatch Then DoCmd.GoToRecord , , acNewRec Else Me.Bookmark = .Bookmark End If End With End If
End Sub
Someday I will get a thorough handle on VBA........sigh....
-- Thanks for taking the time!
CJ --------------------------------------------------------- Know thyself, know thy limits....know thy newsgroups!
|
|
"CJ" <private[ at ]newsgroups.com> wrote in message news:50303CC9-ABB7-406C-8409-E335E3DB449B[ at ]microsoft.com...
[Quoted Text] > Hi Groupies > > I am trying to use Open Arguments to open a form and find a matching > inventory item. If the item does not exist > I want to go to a new record. I borrowed the code from an > old thread but I can not quite get it to work for me. > > I keep getting "Else without If" when I compile the code. > > > Private Sub Form_Load() > > If Len(Me.OpenArgs) > 0 Then > With Me.RecordsetClone > .FindFirst "[Sku Number]=" & Me.OpenArgs > Else <BREAK POINT> > If .NoMatch Then DoCmd.GoToRecord , , acNewRec > Else > Me.Bookmark = .Bookmark > End If > End With > End If > > End Sub
You've got your first Else in an odd place, and an "inline If" where I think you want a "block If". I think this is what you had in mind:
If Len(Me.OpenArgs) > 0 Then
With Me.RecordsetClone .FindFirst "[Sku Number]=" & Me.OpenArgs If .NoMatch Then DoCmd.GoToRecord , , acNewRec Else Me.Bookmark = .Bookmark End If End With
Else
' What do you want to happen if there's no OpenArgs? ' Anything?
End If
-- Dirk Goldgar, MS Access MVP www.datagnostics.com
(please reply to the newsgroup)
|
|
Hi Dirk
Your code worked perfectly, as usual.
If there is no Open Arguments then I want it to go to a new record. So, I added a line after the last Else
If Len(Me.OpenArgs) > 0 Then
With Me.RecordsetClone .FindFirst "[Sku Number]=" & Me.OpenArgs If .NoMatch Then DoCmd.GoToRecord , , acNewRec Else Me.Bookmark = .Bookmark End If End With Else DoCmd.GoToRecord , , acNewRec End If
Thanks again Dirk!!
-- Thanks for taking the time!
CJ --------------------------------------------------------- Know thyself, know thy limits....know thy newsgroups! "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> wrote in message news:uGLMMg0TJHA.5024[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text] > "CJ" <private[ at ]newsgroups.com> wrote in message > news:50303CC9-ABB7-406C-8409-E335E3DB449B[ at ]microsoft.com... >> Hi Groupies >> >> I am trying to use Open Arguments to open a form and find a matching >> inventory item. If the item does not exist >> I want to go to a new record. I borrowed the code from an >> old thread but I can not quite get it to work for me. >> >> I keep getting "Else without If" when I compile the code. >> >> >> Private Sub Form_Load() >> >> If Len(Me.OpenArgs) > 0 Then >> With Me.RecordsetClone >> .FindFirst "[Sku Number]=" & Me.OpenArgs >> Else <BREAK POINT> >> If .NoMatch Then DoCmd.GoToRecord , , acNewRec >> Else >> Me.Bookmark = .Bookmark >> End If >> End With >> End If >> >> End Sub > > > You've got your first Else in an odd place, and an "inline If" where I > think you want a "block If". I think this is what you had in mind: > > If Len(Me.OpenArgs) > 0 Then > > With Me.RecordsetClone > .FindFirst "[Sku Number]=" & Me.OpenArgs > If .NoMatch Then > DoCmd.GoToRecord , , acNewRec > Else > Me.Bookmark = .Bookmark > End If > End With > > Else > > ' What do you want to happen if there's no OpenArgs? > ' Anything? > > End If > > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) >
|
|
.......and then that last line
DoCmd.GoToRecord , , acNewRec
.....decided not to play my little game.
When I double click on one of my items on my form I go straight to a new record.....
What I wanted is, if you access the form from a different route you would go straight to a new record.
-- Thanks for taking the time!
CJ --------------------------------------------------------- Know thyself, know thy limits....know thy newsgroups! "CJ" <private[ at ]newsgroups.com> wrote in message news:2578BB47-98E6-490B-BB3C-98AAD3DB4EE0[ at ]microsoft.com...
[Quoted Text] > Hi Dirk > > Your code worked perfectly, as usual. > > If there is no Open Arguments then I want it to go to a new record. > So, I added a line after the last Else > > > If Len(Me.OpenArgs) > 0 Then > > With Me.RecordsetClone > .FindFirst "[Sku Number]=" & Me.OpenArgs > If .NoMatch Then > DoCmd.GoToRecord , , acNewRec > Else > Me.Bookmark = .Bookmark > End If > End With > Else > DoCmd.GoToRecord , , acNewRec > End If > > Thanks again Dirk!! > > -- > Thanks for taking the time! > > CJ > --------------------------------------------------------- > Know thyself, know thy limits....know thy newsgroups! > "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> wrote in message > news:uGLMMg0TJHA.5024[ at ]TK2MSFTNGP03.phx.gbl... >> "CJ" <private[ at ]newsgroups.com> wrote in message >> news:50303CC9-ABB7-406C-8409-E335E3DB449B[ at ]microsoft.com... >>> Hi Groupies >>> >>> I am trying to use Open Arguments to open a form and find a matching >>> inventory item. If the item does not exist >>> I want to go to a new record. I borrowed the code from an >>> old thread but I can not quite get it to work for me. >>> >>> I keep getting "Else without If" when I compile the code. >>> >>> >>> Private Sub Form_Load() >>> >>> If Len(Me.OpenArgs) > 0 Then >>> With Me.RecordsetClone >>> .FindFirst "[Sku Number]=" & Me.OpenArgs >>> Else <BREAK POINT> >>> If .NoMatch Then DoCmd.GoToRecord , , acNewRec >>> Else >>> Me.Bookmark = .Bookmark >>> End If >>> End With >>> End If >>> >>> End Sub >> >> >> You've got your first Else in an odd place, and an "inline If" where I >> think you want a "block If". I think this is what you had in mind: >> >> If Len(Me.OpenArgs) > 0 Then >> >> With Me.RecordsetClone >> .FindFirst "[Sku Number]=" & Me.OpenArgs >> If .NoMatch Then >> DoCmd.GoToRecord , , acNewRec >> Else >> Me.Bookmark = .Bookmark >> End If >> End With >> >> Else >> >> ' What do you want to happen if there's no OpenArgs? >> ' Anything? >> >> End If >> >> >> -- >> Dirk Goldgar, MS Access MVP >> www.datagnostics.com >> >> (please reply to the newsgroup) >> >
|
|
"CJ" <private[ at ]newsgroups.com> wrote in message news:4398A6B3-1F5B-45AE-BB7E-FC48539BC37B[ at ]microsoft.com...
[Quoted Text] > ......and then that last line > > DoCmd.GoToRecord , , acNewRec > > ....decided not to play my little game.
Huh. I don't see why not. You mean that line executes, but doesn't send the form to the new record?
> When I double click on one of my items on my form > I go straight to a new record..... > > What I wanted is, if you access the form from a different route > you would go straight to a new record.
I'm not understanding this. Where does double-clicking come into it? What are you doing in the double-click event? Are we talking about the same form, or some other form?
-- Dirk Goldgar, MS Access MVP www.datagnostics.com
(please reply to the newsgroup)
|
|
Hi Dirk
Sorry about the lack of info.
I double click on a listbox item on frmTruckLoad that opens frmInventory with it's open arguments.
Here is the code from both forms:
frmTruckLoad:
Private Sub lstTruckInventory_DblClick(Cancel As Integer) Dim stDocName As String Dim stLinkCriteria As String
stDocName = "frmInventory"
stLinkCriteria = "[SKU Number]= '" & Me.lstTruckInventory.Column(0) & "'" DoCmd.OpenForm stDocName, , , stLinkCriteria
frmInventory:
Private Sub Form_Load() If Len(Me.OpenArgs) > 0 Then With Me.RecordsetClone .FindFirst "[Sku Number]=" & Me.OpenArgs If .NoMatch Then DoCmd.GoToRecord , , acNewRec Else Me.Bookmark = .Bookmark End If End With Else If Len(Me.OpenArgs) < 0 Then DoCmd.GoToRecord , , acNewRec End If End If
I need the last ....acNewRec line in case frmInventory is opened via the menu. Then I want to go straight to a new record. At the moment, it is going to the first record in the data source. -- Thanks for taking the time!
CJ --------------------------------------------------------- Know thyself, know thy limits....know thy newsgroups! "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> wrote in message news:ezGyJO9TJHA.5860[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text] > "CJ" <private[ at ]newsgroups.com> wrote in message > news:4398A6B3-1F5B-45AE-BB7E-FC48539BC37B[ at ]microsoft.com... >> ......and then that last line >> >> DoCmd.GoToRecord , , acNewRec >> >> ....decided not to play my little game. > > Huh. I don't see why not. You mean that line executes, but doesn't send > the form to the new record? > >> When I double click on one of my items on my form >> I go straight to a new record..... >> >> What I wanted is, if you access the form from a different route >> you would go straight to a new record. > > I'm not understanding this. Where does double-clicking come into it? > What are you doing in the double-click event? Are we talking about the > same form, or some other form? > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) >
|
|
"CJ" <private[ at ]newsgroups.com> wrote in message news:B09C266E-2D83-4AB8-A880-2E8137173296[ at ]microsoft.com...
[Quoted Text] > Hi Dirk > > Sorry about the lack of info. > > I double click on a listbox item on frmTruckLoad > that opens frmInventory with it's open arguments. > > Here is the code from both forms: > > frmTruckLoad: > > Private Sub lstTruckInventory_DblClick(Cancel As Integer) > Dim stDocName As String > Dim stLinkCriteria As String > > stDocName = "frmInventory" > > stLinkCriteria = "[SKU Number]= '" & Me.lstTruckInventory.Column(0) & "'" > DoCmd.OpenForm stDocName, , , stLinkCriteria > > > frmInventory: > > Private Sub Form_Load() > If Len(Me.OpenArgs) > 0 Then > With Me.RecordsetClone > .FindFirst "[Sku Number]=" & Me.OpenArgs > If .NoMatch Then > DoCmd.GoToRecord , , acNewRec > Else > Me.Bookmark = .Bookmark > End If > End With > Else > If Len(Me.OpenArgs) < 0 Then > DoCmd.GoToRecord , , acNewRec > End If > End If > > I need the last ....acNewRec line in case frmInventory > is opened via the menu. Then I want to go straight to > a new record. At the moment, it is going to the first record > in the data source.
Wait a minute! There's something wrong here. I'm looking at these lines in frmTruckLoad:
> stLinkCriteria = "[SKU Number]= '" & Me.lstTruckInventory.Column(0) & "'" > DoCmd.OpenForm stDocName, , , stLinkCriteria
That does *not* pass the SKU Number in OpenArgs. It passes a "where-condition" that filters the form it's opening so that it shows only the record for the SKU Number that is held in lstTruckInventory.Column(0) -- plus the blank "new record" if the form allows additions. So long as that is what you want, there is no need for any additional code in frmInventory to accomplish it.
If you want to detect, in frmInventory, whether it was opened in this way or not, you could do it like this:
'----- start of code ----- Private Sub Form_Open(Cancel As Integer)
If Me.FilterOn = False Then DoCmd.GoToRecord , , acNewRec End If
End Sub '----- end of code -----
I believe that ought to do it, without the code you currently have in Form_Load.
If that *doesn't* work, you could use OpenArgs the way you have been attempting to do, but (a) you must modify the code in frmTruckLoad to pass the SKU Number in OpenArgs instead of applying a where-condition, and (b) you must modify the code in frmInventory to allow for the apparent fact that SKU Number is a text field.
-- Dirk Goldgar, MS Access MVP www.datagnostics.com
(please reply to the newsgroup)
|
|
Hi Dirk
I used
If Me.FilterOn = False Then DoCmd.GoToRecord , , acNewRec End If
and got rid of the rest of the Load code.
Very neat and tidy.
Again, many many thanks!!
-- Thanks for taking the time!
CJ --------------------------------------------------------- Know thyself, know thy limits....know thy newsgroups! "Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> wrote in message news:%235CMMI%23TJHA.2040[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text] > "CJ" <private[ at ]newsgroups.com> wrote in message > news:B09C266E-2D83-4AB8-A880-2E8137173296[ at ]microsoft.com... >> Hi Dirk >> >> Sorry about the lack of info. >> >> I double click on a listbox item on frmTruckLoad >> that opens frmInventory with it's open arguments. >> >> Here is the code from both forms: >> >> frmTruckLoad: >> >> Private Sub lstTruckInventory_DblClick(Cancel As Integer) >> Dim stDocName As String >> Dim stLinkCriteria As String >> >> stDocName = "frmInventory" >> >> stLinkCriteria = "[SKU Number]= '" & Me.lstTruckInventory.Column(0) & "'" >> DoCmd.OpenForm stDocName, , , stLinkCriteria >> >> >> frmInventory: >> >> Private Sub Form_Load() >> If Len(Me.OpenArgs) > 0 Then >> With Me.RecordsetClone >> .FindFirst "[Sku Number]=" & Me.OpenArgs >> If .NoMatch Then >> DoCmd.GoToRecord , , acNewRec >> Else >> Me.Bookmark = .Bookmark >> End If >> End With >> Else >> If Len(Me.OpenArgs) < 0 Then >> DoCmd.GoToRecord , , acNewRec >> End If >> End If >> >> I need the last ....acNewRec line in case frmInventory >> is opened via the menu. Then I want to go straight to >> a new record. At the moment, it is going to the first record >> in the data source. > > > Wait a minute! There's something wrong here. I'm looking at these lines > in frmTruckLoad: > >> stLinkCriteria = "[SKU Number]= '" & Me.lstTruckInventory.Column(0) & "'" >> DoCmd.OpenForm stDocName, , , stLinkCriteria > > That does *not* pass the SKU Number in OpenArgs. It passes a > "where-condition" that filters the form it's opening so that it shows only > the record for the SKU Number that is held in > lstTruckInventory.Column(0) -- plus the blank "new record" if the form > allows additions. So long as that is what you want, there is no need for > any additional code in frmInventory to accomplish it. > > If you want to detect, in frmInventory, whether it was opened in this way > or not, you could do it like this: > > '----- start of code ----- > Private Sub Form_Open(Cancel As Integer) > > If Me.FilterOn = False Then > DoCmd.GoToRecord , , acNewRec > End If > > End Sub > '----- end of code ----- > > I believe that ought to do it, without the code you currently have in > Form_Load. > > If that *doesn't* work, you could use OpenArgs the way you have been > attempting to do, but (a) you must modify the code in frmTruckLoad to pass > the SKU Number in OpenArgs instead of applying a where-condition, and (b) > you must modify the code in frmInventory to allow for the apparent fact > that SKU Number is a text field. > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) >
|
|
|