Re: Merge two tables
Hi Norie,
Thanks for the reply
The reason I ask for code is that i am using automation and accessing my database from either excel (Mostly) or VB so not from within access
Cheers
Gibbo
Re: Merge two tables
Hi Norie,
Thanks for the reply
The reason I ask for code is that i am using automation and accessing my database from either excel (Mostly) or VB so not from within access
Cheers
Gibbo
All
Can anyone tell me how (or if) I can merge two tables into one please, but i want to be able to do this via code.
The two tables are in different databases but have an identical structure.
Cheers
Gibbo
Re: Transferring data between Access/Excel
Nat
Have a look at the attached, its messy but might give you some ideas
http://www.vbaexpress.com/forum/showthread.php?t=5728
I had a similar problem so have been learning about opening access from within excel and my users only need to see excel (Called Automation)
Note: You do not need access installed to create or deal with data contained in one
Anyway have a look and see what you think
Might give you some ideas
Gibbo
Re: Edit access record
Ok got both bits of code working now as follows
Private Sub CommandButton7_Click()
'edits/updates the current record with values currently shown in the TextBoxes
With rstObj
.Fields("FieldName1") = Me.TextBox1.Text
.Fields("FieldName2") = Me.TextBox2.Text
.Fields("FieldName3") = Me.TextBox3.Text
.Fields("FieldName4") = Me.TextBox4.Text
.Fields("FieldName5") = Me.TextBox5.Text
rstObj.Update
End With
End Sub
Dim rs As ADODB.Recordset
Dim lngBkMark As Variant 'not long
'open the recordset
' move through some records or edit, update
lngBkMark = rs.Bookmark 'set variable to current record
'do some more editing and navigating through recordset
' now go back to desired record
rs.Bookmark = lngBkMark
Display More
Thanks for the help
Gibbo
Re: Edit access record
QuoteDisplay MoreDim rs As ADODB.Recordset
Dim lngBkMark As Long
'open the recordset
' move through some records or edit, update
lngBkMark = rs.Bookmark 'set variable to current record
'do some more editing and navigating through recordset
' now go back to desired record
rs.Bookmark = lngBkMark
I get an error arguments are out of acceptable range or are in conflict with each other
Any Ideas
Cheers
Gibbo
Re: Edit access record
any chance of an example please
Cheers
Gibbo
Re: Edit access record
Ok Norie
Sure you ll find lots wrong with this as i am very new to this idea
the code below is to navigate , delete, create and edit (At least thats the aim)
Thanks for your help
Gibbo
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim intRecNumber As Integer
Private Sub CommandButton1_Click()
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Gibbos.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "tbl_Test", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldName1") = Me.TextBox1.Text
.Fields("FieldName2") = Me.TextBox2.Text
.Fields("FieldName3") = Me.TextBox3.Text
.Fields("FieldName4") = Me.TextBox4.Text
.Fields("FieldName5") = Me.TextBox5.Text
' add more fields if necessary...
.Update ' stores the new record
End With
Call CommandButton4_Click
End Sub
Private Sub CommandButton2_Click()
rs.MovePrevious
intRecNumber = intRecNumber - 1
If Not rs.BOF Then
Call Navigation
Me.Label1.Caption = CStr(intRecNumber) & " of " & rs.RecordCount
Else
CommandButton5_Click
End If
End Sub
Private Sub CommandButton3_Click()
rs.MoveNext
intRecNumber = intRecNumber + 1
If Not rs.EOF Then
Call Navigation
Me.Label1.Caption = CStr(intRecNumber) & " of " & rs.RecordCount
Else
CommandButton6_Click
End If
End Sub
Private Sub CommandButton4_Click()
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
End Sub
Private Sub CommandButton5_Click()
rs.MoveFirst
intRecNumber = 0
Call Navigation
Me.Label1.Caption = "1 of " & rs.RecordCount
End Sub
Private Sub CommandButton6_Click()
rs.MoveLast
intRecNumber = rs.RecordCount
Call Navigation
Me.Label1.Caption = CStr(intRecNumber) & " of " & rs.RecordCount
End Sub
Private Sub CommandButton7_Click()
'edits/updates the current record with values currently shown in the TextBoxes
rs.EditMode
.Fields("FieldName1") = Me.TextBox1.Text
.Fields("FieldName2") = Me.TextBox2.Text
.Fields("FieldName3") = Me.TextBox3.Text
.Fields("FieldName4") = Me.TextBox4.Text
.Fields("FieldName5") = Me.TextBox5.Text
rstObj.Update
End Sub
Private Sub CommandButton8_Click()
'deletes the current record
rs.Delete
End Sub
Private Sub UserForm_Activate()
intRecNumber = 1
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
stDB & ";"
rs.Open "tbl_Test", cn, adOpenStatic, adLockOptimistic, adCmdTable
Me.Label1.Caption = CStr(intRecNumber + 1) & " of " & rs.RecordCount
Me.TextBox1.Value = rs.Fields("FieldName1").Value
Me.TextBox2.Value = rs.Fields("FieldName2").Value
Me.TextBox3.Value = rs.Fields("FieldName3").Value
Me.TextBox4.Value = rs.Fields("FieldName4").Value
Me.TextBox5.Value = rs.Fields("FieldName5").Value
Me.Label1.Caption = "1 of " & rs.RecordCount
' rs.Close
' Set rs = Nothing
' cn.Close
' Set cn = Nothing
End Sub
Private Sub Navigation()
Me.TextBox1.Value = rs.Fields("FieldName1").Value
Me.TextBox2.Value = rs.Fields("FieldName2").Value
Me.TextBox3.Value = rs.Fields("FieldName3").Value
Me.TextBox4.Value = rs.Fields("FieldName4").Value
Me.TextBox5.Value = rs.Fields("FieldName5").Value
End Sub
Display More
Re: Edit access record
Hi Norie, sorry a bit vague
Excel does not recognise .EditMode.
Having read a bit more on this subject I dont think it is as simple as that and think what I am actually looking for is a query
What I want to do is with the record I am viewing from an excel userform, change the content and then save those changes to my access database over-writing the record.
Can you suggest how i can do this or point me to where I can read up on the subject
Cheers
Gibbo
All
I have a user form in excel that accesses an access database and navigates through the records.
Can anyone tell me how i can update a current record please
I tried the code below but get error as it doesnt recognise the command
Thanks in advance
Gibbo
'edits/updates the current record with values currently shown in the TextBoxes
rs.EditMode
.Fields("FieldName1") = Me.TextBox1.Text
.Fields("FieldName2") = Me.TextBox2.Text
.Fields("FieldName3") = Me.TextBox3.Text
.Fields("FieldName4") = Me.TextBox4.Text
.Fields("FieldName5") = Me.TextBox5.Text
rstObj.Update
Re: instr function
If its an excel doc you can use [a1].Value = ThisWorkbook.Path for path and [a2].Value = ThisWorkbook.Name
Re: Insert Rows Based On Values in a Column
Off the top of my head if you want a button and the amount is next to the part number something like below should get you started, not good code though, you should set it up to find the correct cell on the row automatically but i cant remember at the mo how to do that, sorry
[VBA]
Sub Button1_Click()
Dim i As Long
Dim Amount As Long
Amount = ActiveCell.Offset(0, 1).Value
For i = 1 To Amount
ActiveCell.Offset(1, 0).EntireRow.Select
Selection.Insert Shift:=xlDown
Next
End Sub
[/VBA]
Gibbo
Re: update links with a macro
Glad to Help, use the thread tools at the top of the thread to mark it as solved
Cheers
Gibbo
Re: update links with a macro
Try this for starters to give you an idea
[VBA]
Range("C8").Select
Dim i As Integer
Dim WeekNum As Integer
WeekNum = Range("A2")
For i = 1 To WeekNum
If i < 10 Then
ActiveCell.Formula = "='M:\Network\indep\supp1\[0" & i & ".xls]RR'!$F$30"
Else
ActiveCell.Formula = "='M:\Network\indep\supp1\[" & i & ".xls]RR'!$F$30"
End If
ActiveCell.Offset(1, 0).Select
Next i
[/VBA]
Cheers
Gibbo
Re: Search through subfolders for a file type
Ger
I ve been messing with this sort of thing quite a bit lately, if you post exactly what your trying to acheive i may already have something done that will assist you
Gibbo
Re: Search through subfolders for a file type
I ve added a little bit to Andys code so you can select the directory you would like to search, this is the shortest method I am aware of (unless anyone knows a shorter one
Cheers Gibbo
[VBA]
Function GetFolderPath() As String
Dim oShell As Object
Set oShell = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please select folder", 0, "c:\\")
If Not oShell Is Nothing Then
GetFolderPath = oShell.Items.Item.Path
Else
GetFolderPath = vbNullString
End If
Set oShell = Nothing
End Function
Private Sub CommandButton1_Click()
Dim fscTemp As FileSearch
Dim lngIndex As Long
Dim sFolder As String
sFolder = GetFolderPath
If sFolder <> vbNullString Then MsgBox sFolder
Set fscTemp = Application.FileSearch
With fscTemp
.FileType = msoFileTypeExcelWorkbooks
.LookIn = sFolder
.SearchSubFolders = True
.Execute
For lngIndex = 1 To .FoundFiles.Count
ListBox1.AddItem .FoundFiles.Item(lngIndex)
Next
End With
End Sub
[/VBA]
Re: Get a folder name
Have a look at this ongoing thread than may help you, there is a sample attachement http://www.vbaexpress.com/forum/showthread.php?t=4943
Cheers
Gibbo
Re: move based on date
Anyone able to just get me started then?
what i want to have is a userform where i enter a date dd,mm,yyyy and some data and can do this many times
I want to put the date onto sheet 1 as follows
Earliest date always goes in column A3( data in A4): and sort all the other dates (and Data) earliest until latest as they are added leaving a gap between each date
So if i add an earlier date than is already displayed it would add it before that date as follows
so dates would be A3 - gap - C3 - gap - E3 and so on
01/01/2003 - 01/02/2003 - 01/03/2003
Data - Data - Data
Any help with this is greatfully received
:?
Re: check if read only and inform my users
ok That works rather well on my home PC and i ll check it on my works network tomorrow
What can i say
Thanks again
Re: check if read only and inform my users
well that answers that then, many thanks to you all