Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pam Pam is offline
external usenet poster
 
Posts: 128
Default Macro jumps to combobox

I have a problem I can't figure out, and I am seeking your help. I have a
macro that queries an Access database. This part of it runs fine the first
time. The second time it jumps to the combobox code and I can't figure out
why. (I noted where in jumps in the code below). I am not that
knowledgeable in programming and have muddled my way through so far with a
little help from a programmer in getting the code for the Access part, but
even in researching this newsgroup, I can't figure this out. Can you help me?

Thank You, Pam

Sub ProjectData2()
'Finds all data (Used to provide all project numbers to dropdown values)
Dim sWHERE As String
Dim sAccessFile As String
Dim sTable As String
Dim rowx As String
Dim filterrng As String
'Clears data in rows a-j in "Sample" worksheet
Sheets("Sample").Select
Range("A2:j2").Select
Selection.ClearContents

sAccessFile = ThisWorkbook.Path & "\projectestimationdraft1.mdb"
sTable = "All Fields"

' Get rid of existing data in the table starting at row 5
ClearTableData2 5

' Construct a query using data in the table starting at row 2
ConstructQuery2 1, sWHERE

' Get query data from Access and put it in the table starting at row 5
QueryAccessToDataTable2 5, sAccessFile, sTable, sWHERE

'Filters data and updates dropdown values of project numbers
Worksheets("Sample").Select
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
filterrng = Selection.Address
Range(filterrng).AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range( _
"BA6"), Unique:=True
Sheets("Dropdown Values").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents 'it jumps to my combo box
right after here
Sheets("Sample").Select
Range("bA6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Sheets("Dropdown Values").Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
rowx = Selection.End(xlDown).row
With ActiveWorkbook.Names("ProjectNo")
.Name = "ProjectNo"
.RefersToR1C1 = "='Dropdown Values'!R2C1:R" & rowx & "C1"
.Comment = ""
End With
Sheets("Estimate").Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro jumps to combobox

I am going to guess that you have row source and/or controlsource linked to
the cells you are deleting from Sheets("Dropdown Values"). When you delete
the cells with the link, it defaults to the combobox with focus because you
no longer have a data source.

"Pam" wrote:

I have a problem I can't figure out, and I am seeking your help. I have a
macro that queries an Access database. This part of it runs fine the first
time. The second time it jumps to the combobox code and I can't figure out
why. (I noted where in jumps in the code below). I am not that
knowledgeable in programming and have muddled my way through so far with a
little help from a programmer in getting the code for the Access part, but
even in researching this newsgroup, I can't figure this out. Can you help me?

Thank You, Pam

Sub ProjectData2()
'Finds all data (Used to provide all project numbers to dropdown values)
Dim sWHERE As String
Dim sAccessFile As String
Dim sTable As String
Dim rowx As String
Dim filterrng As String
'Clears data in rows a-j in "Sample" worksheet
Sheets("Sample").Select
Range("A2:j2").Select
Selection.ClearContents

sAccessFile = ThisWorkbook.Path & "\projectestimationdraft1.mdb"
sTable = "All Fields"

' Get rid of existing data in the table starting at row 5
ClearTableData2 5

' Construct a query using data in the table starting at row 2
ConstructQuery2 1, sWHERE

' Get query data from Access and put it in the table starting at row 5
QueryAccessToDataTable2 5, sAccessFile, sTable, sWHERE

'Filters data and updates dropdown values of project numbers
Worksheets("Sample").Select
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
filterrng = Selection.Address
Range(filterrng).AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range( _
"BA6"), Unique:=True
Sheets("Dropdown Values").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents 'it jumps to my combo box
right after here
Sheets("Sample").Select
Range("bA6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Sheets("Dropdown Values").Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
rowx = Selection.End(xlDown).row
With ActiveWorkbook.Names("ProjectNo")
.Name = "ProjectNo"
.RefersToR1C1 = "='Dropdown Values'!R2C1:R" & rowx & "C1"
.Comment = ""
End With
Sheets("Estimate").Select
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
Pam Pam is offline
external usenet poster
 
Posts: 128
Default Macro jumps to combobox

Yes, you are right. In the properties box for the combobox, the RowSource is
the range name. I did it this way because the range can change. Can you
suggest a fix? Any help would be appreciated.

Thank You,

Pam

"JLGWhiz" wrote:

I am going to guess that you have row source and/or controlsource linked to
the cells you are deleting from Sheets("Dropdown Values"). When you delete
the cells with the link, it defaults to the combobox with focus because you
no longer have a data source.

"Pam" wrote:

I have a problem I can't figure out, and I am seeking your help. I have a
macro that queries an Access database. This part of it runs fine the first
time. The second time it jumps to the combobox code and I can't figure out
why. (I noted where in jumps in the code below). I am not that
knowledgeable in programming and have muddled my way through so far with a
little help from a programmer in getting the code for the Access part, but
even in researching this newsgroup, I can't figure this out. Can you help me?

Thank You, Pam

Sub ProjectData2()
'Finds all data (Used to provide all project numbers to dropdown values)
Dim sWHERE As String
Dim sAccessFile As String
Dim sTable As String
Dim rowx As String
Dim filterrng As String
'Clears data in rows a-j in "Sample" worksheet
Sheets("Sample").Select
Range("A2:j2").Select
Selection.ClearContents

sAccessFile = ThisWorkbook.Path & "\projectestimationdraft1.mdb"
sTable = "All Fields"

' Get rid of existing data in the table starting at row 5
ClearTableData2 5

' Construct a query using data in the table starting at row 2
ConstructQuery2 1, sWHERE

' Get query data from Access and put it in the table starting at row 5
QueryAccessToDataTable2 5, sAccessFile, sTable, sWHERE

'Filters data and updates dropdown values of project numbers
Worksheets("Sample").Select
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
filterrng = Selection.Address
Range(filterrng).AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range( _
"BA6"), Unique:=True
Sheets("Dropdown Values").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents 'it jumps to my combo box
right after here
Sheets("Sample").Select
Range("bA6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Sheets("Dropdown Values").Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
rowx = Selection.End(xlDown).row
With ActiveWorkbook.Names("ProjectNo")
.Name = "ProjectNo"
.RefersToR1C1 = "='Dropdown Values'!R2C1:R" & rowx & "C1"
.Comment = ""
End With
Sheets("Estimate").Select
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
Pam Pam is offline
external usenet poster
 
Posts: 128
Default Macro jumps to combobox

I tried changing my code so it just overrights what's in the named range.
When I start the macro the second time I can tell right away that it's not
going to work because the first form displays on the left side of the screen
instead of the center, and then my combo box has the last entry in it with a
blank drop down. What am I doing wrong?

Pam

"Pam" wrote:

Yes, you are right. In the properties box for the combobox, the RowSource is
the range name. I did it this way because the range can change. Can you
suggest a fix? Any help would be appreciated.

Thank You,

Pam

"JLGWhiz" wrote:

I am going to guess that you have row source and/or controlsource linked to
the cells you are deleting from Sheets("Dropdown Values"). When you delete
the cells with the link, it defaults to the combobox with focus because you
no longer have a data source.

"Pam" wrote:

I have a problem I can't figure out, and I am seeking your help. I have a
macro that queries an Access database. This part of it runs fine the first
time. The second time it jumps to the combobox code and I can't figure out
why. (I noted where in jumps in the code below). I am not that
knowledgeable in programming and have muddled my way through so far with a
little help from a programmer in getting the code for the Access part, but
even in researching this newsgroup, I can't figure this out. Can you help me?

Thank You, Pam

Sub ProjectData2()
'Finds all data (Used to provide all project numbers to dropdown values)
Dim sWHERE As String
Dim sAccessFile As String
Dim sTable As String
Dim rowx As String
Dim filterrng As String
'Clears data in rows a-j in "Sample" worksheet
Sheets("Sample").Select
Range("A2:j2").Select
Selection.ClearContents

sAccessFile = ThisWorkbook.Path & "\projectestimationdraft1.mdb"
sTable = "All Fields"

' Get rid of existing data in the table starting at row 5
ClearTableData2 5

' Construct a query using data in the table starting at row 2
ConstructQuery2 1, sWHERE

' Get query data from Access and put it in the table starting at row 5
QueryAccessToDataTable2 5, sAccessFile, sTable, sWHERE

'Filters data and updates dropdown values of project numbers
Worksheets("Sample").Select
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
filterrng = Selection.Address
Range(filterrng).AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range( _
"BA6"), Unique:=True
Sheets("Dropdown Values").Select
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents 'it jumps to my combo box
right after here
Sheets("Sample").Select
Range("bA6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Sheets("Dropdown Values").Select
Range("A2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
rowx = Selection.End(xlDown).row
With ActiveWorkbook.Names("ProjectNo")
.Name = "ProjectNo"
.RefersToR1C1 = "='Dropdown Values'!R2C1:R" & rowx & "C1"
.Comment = ""
End With
Sheets("Estimate").Select
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab Jumps 13 Cells when hit rcamron Excel Discussion (Misc queries) 4 December 12th 09 05:22 PM
Macro unexpectedly jumps to other macros and functions Options MarkM[_5_] Excel Programming 1 December 7th 07 03:24 AM
Scoll bar jumps to top lyk Excel Discussion (Misc queries) 0 October 5th 07 08:48 PM
Autofilter jumps to end of row, why? Pierre Excel Discussion (Misc queries) 0 February 7th 07 03:35 PM
Macro unexpectedly jumps to other macros and functions Jeff Wright[_2_] Excel Programming 3 November 25th 04 01:47 PM


All times are GMT +1. The time now is 05:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"