Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo und Guten Tach,

ich hab jetzt ein Problem und das ist so:

in einer Access Datenbank ist eine Tabelle die mit Daten gefüllt ist. Davon sind einige mit dem Datumsformat die die Werte xx.xx.2099 enthalten (xx = egal was da ist). So die Aufgabe ist nun per Update die Datumswerte die xx.xx.2099 auf xx.xx.2049 zu setzten:

Folgendes hab ich schon gemacht:



Sub RunSQL(sql As String)

    Application.CurrentProject.Connection.Execute "BEGIN TRANSACTION"

    Application.CurrentProject.Connection.Execute sql

    Application.CurrentProject.Connection.Execute "COMMIT"

End Sub


Sub Date_Year_Corr_Module()


    Dim sql As String


    ' Lastenheft Start/Plan/Ist korrigieren

    sql = "UPDATE Grunddaten SET Grunddaten.[Lastenheft Start] = #12/31/2049# "

    sql = sql + "WHERE (((Grunddaten.[Lastenheft Start]) Like #12/31/2099#))"

    RunSQL (sql)

    sql = "UPDATE Grunddaten SET Grunddaten.[Lastenheft Plan] = #12/31/2049# "

    sql = sql + "WHERE (((Grunddaten.[Lastenheft Plan]) Like #12/31/2099#))"

    RunSQL (sql)

    sql = "UPDATE Grunddaten SET Grunddaten.[Lastenheft Ist] = #12/31/2049# "

    sql = sql + "WHERE (((Grunddaten.[Lastenheft Ist]) Like #12/31/2099#))"

    RunSQL (sql)


End Sub

Problem dabei ist das ich jetzt nur die Daten 31.12.2099 durch 31.12.2049 ersetzt bekomme. Wie schaffe ich es das ich alle Jahreszahlen 2099 durch 2049 zu ersetzten, ohne die Tage und Monate zu beeinflussen. Die Funktion to_date kennt er nicht... oder ich hab was falsch gemacht....

Danke.

|Edit:|

Ich hab XP Pro und verwende MS Access 2003

|:Edit|

  • Autor

Hallo,

ich werd jetzt mal folgendes Versuchen:

Ich bau mir erst einen Dynamischen SQL-Update zusammen...


Sub all_date(setvalue As String)


Dim day As Integer

Dim month As Integer

Dim sql As String


day = 1

month = 1


For month = 1 To 12

    For day = 1 To 31

      sql = "UPDATE Grunddaten set " & setvalue & " = #" & month & "/" & day & "/2049# " _

           & "WHERE " & setvalue & " LIKE #" & month & "/" & day & "/2099# "

      RunSQL (sql)

    Next day

Next month


End Sub

dann hoff ich das es funktioniert...

  • Autor

Hallo,

habs jetzt doch selber geschafft.

Hier die Lösung für alle die die eine ähnliches Problem haben:



'Sendet den SQL Befehl an Access'
Sub RunSQL(sql As String)

Application.CurrentProject.Connection.Execute "BEGIN TRANSACTION"
Application.CurrentProject.Connection.Execute sql
Application.CurrentProject.Connection.Execute "COMMIT"

End Sub

'Geht jedes Datum vom 01.01.2099 bis 31.12.2099 durch'
'und setzt die Jahreszahl auf 2049. Datumsüberprüfung wird'
'auch durchgeführt, auf Schaltjahr musste ich nicht prüfen da'
'das Jahr 2099 und 2049 kein Schaltjahr sein'
Sub all_date(setvalue As String)

Dim day As Integer
Dim maxdays As Integer
Dim month As Integer
Dim sql As String

day = 1
month = 1

For month = 1 To 12

If (month = 2) Then
maxdays = 28
ElseIf ((month = 4) Or (month = 6) Or (month = 7) Or (month = 9) Or (month = 11)) Then
maxdays = 30
Else
maxdays = 31
End If

For day = 1 To maxdays
sql = "UPDATE Grunddaten set " & setvalue & " = #"

If (month < 10) Then
sql = sql + "0"
End If

sql = sql + "" & month & "/"

If (day < 10) Then
sql = sql + "0"
End If

sql = sql + "" & day & "/2049# WHERE " & setvalue & " LIKE #"

If (month < 10) Then
sql = sql + "0"
End If

sql = sql + "" & month & "/"

If (day < 10) Then
sql = sql + "0"
End If

sql = sql + "" & day & "/2099# "

RunSQL (sql)
Next day
Next month

End Sub

'Starte das ganze '
Sub Date_Year_Corr_Module()

Dim sql As String
Dim antwort As Integer

' Lastenheft Start/Plan/Ist korrigieren

all_date ("Grunddaten.[Lastenheft Start]")
all_date ("Grunddaten.[Lastenheft Plan]")
all_date ("Grunddaten.[Lastenheft Ist]")

antwort = MsgBox("Datum wurde korregiert!", vbOKOnly, "O.k.", 0, 0)

End Sub
[/PHP]

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.