Compile error: Duplicate declaration in current scope" (1 Viewer)

irunergoiam

Registered User.
Local time
Today, 04:24
Joined
May 30, 2009
Messages
76
I'm getting a compile error: Duplicate declaration in scope. I'm pretty sure it has something to do with me having the DimstDocName As String (in red) in there twice for two different procedures (one to run a delete query and the second to open the form again after closing).

There's something I'm missing, but I'm still just cutting my teeth with this. Any help would be most appreciated! Thanks...


Dim stDocName As String
stDocName = "1SARFPLDeptPositionSystemPermissions-DeleteNullValues"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Me.cmbSys1 = ""
Me.cmbPermission1 = ""
Me.cmbSys2 = ""
Me.cmbPermission2 = ""
Me.cmbSys3 = ""
Me.cmbPermission3 = ""
Me.cmbSys4 = ""
Me.cmbPermission4 = ""
Me.cmbSys5 = ""
Me.cmbPermission5 = ""
Me.cmbSys6 = ""
Me.cmbPermission6 = ""
Me.cmbSys7 = ""
Me.cmbPermission7 = ""
Me.cmbSys8 = ""
Me.cmbPermission8 = ""
Me.cmbSys9 = ""
Me.cmbPermission9 = ""
Me.cmbSys10 = ""
Me.cmbPermission10 = ""


Me.Refresh

DoCmd.Close

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSystems"
DoCmd.OpenForm stDocName, , , stLinkCriteria

MsgBox (" Selected systems successfully added to position template. Add additional system(s)")

DoCmd.SetWarnings True
End If
End Sub
 

boblarson

Smeghead
Local time
Today, 05:24
Joined
Jan 12, 2001
Messages
32,059
If it is in the same procedure, just declare it once and then reuse it. No need to declare it again.
 

irunergoiam

Registered User.
Local time
Today, 04:24
Joined
May 30, 2009
Messages
76
I guess I need a little more hand-holding on this one. This is in an event on a form and there are two things I want to happen: 1) First, run the delete query and 2) then close the form and open it back up.

Not really sure what the code should look like to get both of these things to happen?

Dim stDocName As String
stDocName = "1SARFPLDeptPositionSystemPermissions-DeleteNullValues"
DoCmd.OpenQuery stDocName, acNormal, acEdit

....

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSystems"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:24
Joined
Sep 12, 2006
Messages
15,642
you dont need to DIM it twice

DIM allocates space on the stack for a variable, assigning the variable fills that space

so

dim myvar as long 'creates the variable myvar

myvar = 12 'uses it
myvar = 20 'changes it

ie - you dont need to dim it again, and indeed it is an error to try to dim it again, as you have seen
 

Users who are viewing this thread

Top Bottom